Update cyclone.js

This commit is contained in:
Green! 2022-07-25 19:10:49 -04:00 committed by GitHub
parent 8a0099a6cf
commit 0d9d042a14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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