Update cyclone.js
This commit is contained in:
parent
8a0099a6cf
commit
0d9d042a14
1 changed files with 299 additions and 254 deletions
|
|
@ -115,7 +115,7 @@ class CSSRewriter extends Cyclone {
|
|||
|
||||
var prop = styles.getPropertyValue('background-image')
|
||||
var name = "background-image"
|
||||
console.log(prop)
|
||||
|
||||
if (prop == "") {
|
||||
if (!styles.getPropertyValue('background') == "") {
|
||||
prop = styles.getPropertyValue('background')
|
||||
|
|
@ -126,8 +126,6 @@ class CSSRewriter extends Cyclone {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(name);
|
||||
|
||||
if (prop.includes("url(")) {
|
||||
var start = prop.indexOf('url(') + 4
|
||||
var end = prop.indexOf(')') - 4
|
||||
|
|
@ -136,10 +134,8 @@ class CSSRewriter extends Cyclone {
|
|||
|
||||
if (url.startsWith(location.origin)) {
|
||||
url = url.split(location.origin)
|
||||
console.log("Relative URL", url);
|
||||
} else {
|
||||
url = url.slice(url.indexOf(location.origin));
|
||||
console.log("Absolute URL:",url)
|
||||
}
|
||||
|
||||
url = this.rewriteUrl(url)
|
||||
|
|
@ -151,22 +147,65 @@ class CSSRewriter extends Cyclone {
|
|||
// JS
|
||||
|
||||
class JavaScriptRewriter extends Cyclone {
|
||||
constructor(proxy) {
|
||||
super();
|
||||
//Proxied methods
|
||||
this.setAttrCy = HTMLElement.prototype.setAttribute;
|
||||
this.getAttrCy = HTMLElement.prototype.getAttribute;
|
||||
this.proxy = proxy
|
||||
}
|
||||
|
||||
rewriteJavascript(js) {
|
||||
var javascript = js.replace('window.location', 'document._dlocation')
|
||||
javascript = javascript.replace('document.location', 'document._dlocation')
|
||||
javascript = javascript.replace('location.', 'document._location.')
|
||||
return javascript
|
||||
}
|
||||
|
||||
setAttribute(attr, value, mode) {
|
||||
const setAttrCy = HTMLElement.prototype.setAttribute;
|
||||
|
||||
if (mode) {
|
||||
this.setAttrCy.call(this, attr, value);
|
||||
} else {
|
||||
var url = attr
|
||||
if (cyclone.targetAttrs.includes(attr)) {
|
||||
url = cyclone.rewriteUrl(url);
|
||||
}
|
||||
|
||||
setAttrCy.call(this, attr, value);
|
||||
}
|
||||
}
|
||||
|
||||
getAttribute(attrN, mode) {
|
||||
const getAttrCy = HTMLElement.prototype.getAttribute;
|
||||
|
||||
if (mode) {
|
||||
return getAttrCy.call(this, attrN);
|
||||
} else {
|
||||
var val = getAttrCy.call(this, attrN);
|
||||
if (cyclone.targetAttrs.includes(attrN)) {
|
||||
val = getAttrCy.call(this, 'data-origin-' + attrN);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HTML
|
||||
class HTMLRewriter extends Cyclone {
|
||||
rewriteElement(element) {
|
||||
var targetAttrs = this.targetAttrs;
|
||||
const attrs = [...element.attributes].reduce((attrs, attribute) => {
|
||||
var attrs;
|
||||
try {
|
||||
attrs = [...element.attributes || {}].reduce((attrs, attribute) => {
|
||||
attrs[attribute.name] = attribute.value;
|
||||
return attrs;
|
||||
}, {});
|
||||
} catch {
|
||||
attrs = {};
|
||||
}
|
||||
|
||||
var elementAttributes = [];
|
||||
|
||||
|
|
@ -266,8 +305,8 @@ var CWOriginal = Object.getOwnPropertyDescriptor(window.HTMLIFrameElement.protot
|
|||
|
||||
Object.defineProperty(window.HTMLIFrameElement.prototype, 'contentWindow', {
|
||||
get() {
|
||||
var iWindow = CWOriginal.get.call(this)
|
||||
cyclone.rewriteiFrame(iWindow)
|
||||
var iWindow = CWOriginal.get.call(this);
|
||||
htmlRewriter.rewriteiFrame(iWindow);
|
||||
|
||||
return iWindow
|
||||
},
|
||||
|
|
@ -340,7 +379,17 @@ function openNewTab(url, target, features) {
|
|||
|
||||
window.open = openNewTab;
|
||||
|
||||
htmlRewriter.rewriteDocument();
|
||||
window.onload = function() {
|
||||
for (var i = 0; i < 12; i++) {
|
||||
setTimeout(()=>{
|
||||
htmlRewriter.rewriteDocument();
|
||||
},500)
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
htmlRewriter.rewriteDocument();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
let mutationE = new MutationObserver((mutationList, observer) => {
|
||||
for (const mutation of mutationList) {
|
||||
|
|
@ -353,10 +402,6 @@ let mutationE = new MutationObserver((mutationList, observer) => {
|
|||
subtree: true
|
||||
})
|
||||
|
||||
setInterval(function() {
|
||||
htmlRewriter.rewriteDocument();
|
||||
}, 10000)
|
||||
|
||||
//For intercepting all requests
|
||||
if (!document.serviceWorkerRegistered) {
|
||||
if ('serviceWorker' in navigator) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue