Update cyclone.js

This commit is contained in:
Green! 2022-08-01 15:39:15 -04:00 committed by GitHub
parent 0d9d042a14
commit 65605917a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ class Cyclone {
this.tmp = location.protocol + "//" + this.tmp
document._location = new URL(this.tmp);
var l = new URL(this.tmp);
this.url = new URL(document._location.href);
@ -34,15 +35,34 @@ class Cyclone {
document.cycloneInjected = true
}
/*const LocationHandler = {
const LocationHandler = {
get(target, prop, reciver) {
return loc[prop]
return document._location[prop]
},
set(target, prop, val) {
return 'hi'
return false
}
}
document._location = new Proxy(LocationHandler, loc)*/
//const locProxy = new Proxy(document.location, LocationHandler)
Object.defineProperty(document, '_location', {
writable: true,
configurable: true,
enumerable: true,
value: l
});
Object.defineProperty(window.document, '_location', {
writable: true,
configurable: true,
enumerable: true,
value: l
});
Object.defineProperty(window, '_location', {
writable: true,
configurable: true,
enumerable: true,
value: l
});
}
rewriteUrl(link) {
@ -156,9 +176,9 @@ class JavaScriptRewriter extends Cyclone {
}
rewriteJavascript(js) {
var javascript = js.replace('window.location', 'document._dlocation')
javascript = javascript.replace('document.location', 'document._dlocation')
javascript = javascript.replace('location.', 'document._location.')
var javascript = js.replace(/window\.location/g, 'window._dlocation')
javascript = javascript.replace(/document\.location/g, 'document._dlocation')
javascript = javascript.replace(/location\./g, '_location.')
return javascript
}
@ -207,6 +227,8 @@ class HTMLRewriter extends Cyclone {
attrs = {};
}
if (element.__proto__.getAttribute) {
var jsWrite = new JavaScriptRewriter();
var elementAttributes = [];
for (var i = 0; i < targetAttrs.length; i++) {
@ -214,7 +236,7 @@ class HTMLRewriter extends Cyclone {
var attrName = Object.keys(attrs)[i];
var data = {
name: attr,
value: element.getAttribute('data-origin-' + attr) || element.getAttribute(attr)
value: element.getAttribute('data-origin-' + attr, 'cyclone') || element.getAttribute(attr, 'cyclone')
}
if (data.value) {
@ -222,11 +244,11 @@ class HTMLRewriter extends Cyclone {
}
if (element.nonce) {
element.setAttribute('nononce', element.nonce)
element.setAttribute('nononce', element.nonce, '')
element.removeAttribute('nonce')
}
if (element.integrity) {
element.setAttribute('nointegrity', element.integrity)
element.setAttribute('nointegrity', element.integrity, '')
element.removeAttribute('integrity')
}
@ -243,19 +265,20 @@ class HTMLRewriter extends Cyclone {
}
for (var i = 0; i < elementAttributes.length; i++) {
var attr = elementAttributes[i]
var attr = elementAttributes[i];
var attrName = attr.name;
var value = attr.value;
var bareValue = this.rewriteUrl(value);
if (attrName == "srcset") {
this.rewriteSrcset(value);
if (attrName == "srcset" || attrName == 'srcset') {
bareValue = this.rewriteSrcset(value);
}
element.setAttribute(attrName, bareValue);
element.setAttribute("data-origin-" + attrName, value);
}
}
}
rewriteDocument() {
var docElements = document.querySelectorAll('*');
@ -292,15 +315,21 @@ window.fetch = async (...args) => {
}
const MessageIntercept = window.postMessage;
window.postMessage = (...args) => {
const messageInterceptionFunc = (...args) => {
let [message, target, config] = args;
target = cyclone.rewriteUrl(target);
const response = MessageIntercept(message, target, config);
console.log(response);
return response;
}
Object.defineProperty(window, 'postMessage', {
writable: false,
value: messageInterceptionFunc
}
)
var CWOriginal = Object.getOwnPropertyDescriptor(window.HTMLIFrameElement.prototype, 'contentWindow')
Object.defineProperty(window.HTMLIFrameElement.prototype, 'contentWindow', {
@ -380,15 +409,11 @@ function openNewTab(url, target, features) {
window.open = openNewTab;
window.onload = function() {
for (var i = 0; i < 12; i++) {
for (var i = 0; i < 50; i++) {
setTimeout(() => {
htmlRewriter.rewriteDocument();
}, 500)
}
setInterval(function() {
htmlRewriter.rewriteDocument();
}, 3000);
}
let mutationE = new MutationObserver((mutationList, observer) => {