Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sebgroup/document-write-intervene

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sebgroup/document-write-intervene - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

.babelrc

20

lib/documentWrite.js

@@ -1,16 +0,20 @@

const { isScript, injectScript } = require('./script')
"use strict";
function injectMarkup (markup) {
const body = document.getElementsByTagName('body')[0]
body.insertAdjacentHTML('afterbegin', markup)
var _require = require('./script'),
isScript = _require.isScript,
injectScript = _require.injectScript;
function injectMarkup(markup) {
var body = document.getElementsByTagName('body')[0];
body.insertAdjacentHTML('afterbegin', markup);
}
function documentWrite (markup) {
function documentWrite(markup) {
if (isScript(markup)) {
return injectScript(markup)
return injectScript(markup);
}
return injectMarkup(markup)
return injectMarkup(markup);
}
module.exports = documentWrite
module.exports = documentWrite;

28

lib/intervene.js

@@ -1,22 +0,26 @@

const documentWrite = require('./documentWrite')
"use strict";
function hasDocumentWriteCapability () {
let result
var documentWrite = require('./documentWrite');
function hasDocumentWriteCapability() {
var result;
try {
result =
document && document.write && typeof document.write === 'function'
result = document && document.write && typeof document.write === 'function';
} catch (ex) {
result = false
result = false;
}
return result
return result;
}
function intervene () {
function intervene() {
if (!hasDocumentWriteCapability()) {
return false
return false;
}
document.write = documentWrite
return true
document.write = documentWrite;
return true;
}
module.exports = intervene
module.exports = intervene;

@@ -1,21 +0,23 @@

const scriptTag = /<script[\s\S]*?>[\s\S]*?<\/script>/gi
const srcProp = /<script.*?src="(.*?)"/gmi
"use strict";
function isScript (value) {
return value.match(scriptTag) && value.match(srcProp)
var scriptTag = /<script[\s\S]*?>[\s\S]*?<\/script>/gi;
var srcProp = /<script.*?src="(.*?)"/gmi;
function isScript(value) {
return value.match(scriptTag) && value.match(srcProp);
}
function injectScript (markup) {
const matches = srcProp.exec(markup)
const src = matches[1]
const script = document.createElement('script')
script.type = 'text/javascript'
script.src = src
const body = document.getElementsByTagName('body')[0]
body.appendChild(script)
function injectScript(markup) {
var matches = srcProp.exec(markup);
var src = matches[1];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
var body = document.getElementsByTagName('body')[0];
body.appendChild(script);
}
module.exports = {
isScript,
injectScript
}
isScript: isScript,
injectScript: injectScript
};
{
"name": "@sebgroup/document-write-intervene",
"version": "2.0.0",
"version": "3.0.0",
"description": "Prevent document write from writing to your document and instead insert a new script to the dom.",
"main": "index.js",
"main": "lib/index.js",
"scripts": {
"test": "mocha test/unit",
"test:watch": "mocha test/unit --watch",
"e2e": "mocha test/e2e/specs",
"webdriver:start": "webdriver-manager update && webdriver-manager start",
"e2e:chrome": "mocha --timeout 15000 test/e2e/specs/chrome",
"e2e:ie": "mocha --timeout 15000 test/e2e/specs/ie",
"webdriver:chrome": "webdriver-manager update --chrome && webdriver-manager start",
"webdriver:ie": "webdriver-manager update --ie && webdriver-manager start --ie test/e2e/IEDriverServer.exe",
"commit": "git-cz",
"travis-deploy-once": "travis-deploy-once --pro",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"build": "babel src --out-dir lib && cp index.d.ts lib"
},

@@ -27,2 +30,5 @@ "publishConfig": {

"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@commitlint/cli": "^7.2.0",

@@ -29,0 +35,0 @@ "@commitlint/config-conventional": "^7.1.2",

# document-write-intervene
[![Build Status](https://travis-ci.com/sebgroup/document-write-intervene.svg?token=tzrdkWGEu776AVobzRhp&branch=master)](https://travis-ci.com/sebgroup/document-write-intervene)

@@ -8,9 +9,9 @@ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

It checks if the markup is a `<script>` tag and will load it asynchronous.
It checks if the markup is a `<script>` tag and will load it asynchronous.
Otherwise it will insert the contents using `insertAdjacentHTML` on the `body`
Tested inside an Angular project.
Tested inside an Angular project.
It should work seamlessly with a React project.
It should work seamlessly with a React project.

@@ -42,12 +43,26 @@ Otherwise you could have a look at `browserify` to integrate it in your project

E2E tests:
#### E2E tests:
- Chrome tests:
```
$ npm run webdriver:start
$ npm run webdriver:chrome
```
and then
and then
```
$ npm run e2e
$ npm run e2e:chrome
```
- Internet Explorer tests:
```
$ npm run webdriver:ie
```
and then
```
$ npm run e2e:ie
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc