From aed7a57bab4fc4dc6900630ed6b27c93954b441a Mon Sep 17 00:00:00 2001 From: NotAProton Date: Wed, 15 Dec 2021 23:14:39 +0530 Subject: [PATCH 1/3] Implement ffclipboard --- src/js/background.js | 11 ++++++++ src/js/content_script.js | 43 +++++++++++++++++++++---------- src/js/injection_script.js | 52 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 4104ad89f..c4ca142dc 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -51,6 +51,17 @@ brws.runtime.onInstalled.addListener(details=>{ { brws.tabs.create({url:"https://fastforward.team/firstrun"}) } + //init clipboard + chrome.storage.local.get({ff_clipboard: "{}"}, function(data) { + chrome.storage.local.set({ff_clipboard: data.ff_clipboard}, function() { + })}) +}) + +//clean clipboard on startup +brws.runtime.onStartup.addListener(() => { + chrome.storage.local.get({ff_clipboard: "{}"}, function(data) { + chrome.storage.local.set({ff_clipboard: data.ff_clipboard}, function() { + })}) }) // Uninstall handler diff --git a/src/js/content_script.js b/src/js/content_script.js index 4cb399a31..f021ea318 100644 --- a/src/js/content_script.js +++ b/src/js/content_script.js @@ -1,5 +1,5 @@ //If you want to add your own bypass, go to injection_script.js -if(document instanceof HTMLDocument) +if(document instanceof Document) { let clipboardIndex=location.hash.indexOf("#bypassClipboard="),ignoreCrowdBypass=false,bypassClipboard="" if(location.hash.substr(-18)=="#ignoreCrowdBypass") @@ -117,19 +117,34 @@ if(document instanceof HTMLDocument) crowdPath=location.pathname.substr(1), referer=location.href - let script=document.createElement("script") - script.innerHTML=`(()=>{ - const crowdEnabled=`+(res.crowdEnabled?"true":"false")+`, - ignoreCrowdBypass=`+(ignoreCrowdBypass?"true":"false")+`, - bypassClipboard="`+bypassClipboard.split("\\").join("\\\\").split("\"").join("\\\"")+`" - if(location.href=="https://universal-bypass.org/firstrun") - { - location.replace("https://universal-bypass.org/firstrun?1") - return + //ffclipboard reciever + window.addEventListener("message", function(event) { + // We only accept messages from ourselves + if (event.source != window) { + return; + } + if (event.data.type === "ffclipboardSet") { + brws.storage.local.set({ff_clipboard: event.data.text}) } - `+res.injectionScript+` - })()` - script=document.documentElement.appendChild(script) - setTimeout(()=>document.documentElement.removeChild(script),10) + }); + brws.storage.local.get('ff_clipboard', function(result) { + ffClipboard_stored = result.ff_clipboard + ffClipboard_stored = encodeURIComponent(ffClipboard_stored) + let script=document.createElement("script") + script.innerHTML=`(()=>{ + const crowdEnabled=`+(res.crowdEnabled?"true":"false")+`, + ignoreCrowdBypass=`+(ignoreCrowdBypass?"true":"false")+`, + bypassClipboard="`+bypassClipboard.split("\\").join("\\\\").split("\"").join("\\\"")+`" + let ffClipboard_stored="`+ffClipboard_stored+`" + if(location.href=="https://universal-bypass.org/firstrun") + { + location.replace("https://universal-bypass.org/firstrun?1") + return + } + `+res.injectionScript+` + })()` + script=document.documentElement.appendChild(script) + setTimeout(()=>document.documentElement.removeChild(script),10) + }); }) } diff --git a/src/js/injection_script.js b/src/js/injection_script.js index 556df28ab..b897a2968 100644 --- a/src/js/injection_script.js +++ b/src/js/injection_script.js @@ -286,6 +286,58 @@ persistHash=h=>ensureDomLoaded(()=>{ document.querySelectorAll("form[action]").forEach(e=>e.action+="#"+h) document.querySelectorAll("a[href]").forEach(e=>e.href+="#"+h) }) + +const ffClipboard = function() {} +ffClipboard_stored = decodeURIComponent(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js +//returns an ffclipboard entry, if id does not exist, returns null +ffClipboard.get =(id) => { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch(e) { + return e + } + if (ffClipboardObj === null) { + ffClipboardObj = {} + } + if (!(id in ffClipboardObj)) { + return null + } + return ffClipboardObj[id] +} +//sets ffclipboard contents, if id does not exist, creates it +ffClipboard.set =(id, value) => { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch(e) { + return e + } + + if (ffClipboardObj === null) { + ffClipboardObj = {} + } + ffClipboardObj[id] = value + let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } + window.postMessage(message, "*") //send message to content script +} +//deletes ffclipboard contents and frees up storage , if id does not exist, does nothing +ffClipboard.free =(id) => { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch(e) { + return e + } + + if (ffClipboardObj === null) { + ffClipboardObj = {} + } + if (!(id in ffClipboardObj)) { + return + } + delete ffClipboardObj[id] + let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } + window.postMessage(message, "*") +} + let navigated=false, bypassed=false, domain=location.hostname, From aa40abeddc8684f37446e97ae4c61f1f0c3745dc Mon Sep 17 00:00:00 2001 From: NotAProton Date: Thu, 16 Dec 2021 10:21:55 +0530 Subject: [PATCH 2/3] Improve URI encoding of storage injection --- src/js/content_script.js | 4 +++- src/js/injection_script.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/js/content_script.js b/src/js/content_script.js index f021ea318..7d338d856 100644 --- a/src/js/content_script.js +++ b/src/js/content_script.js @@ -129,7 +129,9 @@ if(document instanceof Document) }); brws.storage.local.get('ff_clipboard', function(result) { ffClipboard_stored = result.ff_clipboard - ffClipboard_stored = encodeURIComponent(ffClipboard_stored) + + //encodeURIcomponent and replace whatever's not encoded, https://stackoverflow.com/a/16435373/17117909 + ffClipboard_stored = encodeURIComponent(ffClipboard_stored).replace(/\-/g, "%2D").replace(/\_/g, "%5F").replace(/\./g, "%2E").replace(/\!/g, "%21").replace(/\~/g, "%7E").replace(/\*/g, "%2A").replace(/\'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29") let script=document.createElement("script") script.innerHTML=`(()=>{ const crowdEnabled=`+(res.crowdEnabled?"true":"false")+`, diff --git a/src/js/injection_script.js b/src/js/injection_script.js index b897a2968..577d2b7d5 100644 --- a/src/js/injection_script.js +++ b/src/js/injection_script.js @@ -285,10 +285,19 @@ backgroundScriptBypassClipboard=c=>{ persistHash=h=>ensureDomLoaded(()=>{ document.querySelectorAll("form[action]").forEach(e=>e.action+="#"+h) document.querySelectorAll("a[href]").forEach(e=>e.href+="#"+h) -}) +}), +//decodes https://stackoverflow.com/a/16435373/17117909 +decodeURIEncodedMod=(s)=>{ + try{ + return decodeURIComponent(s.replace(/\%2D/g, "-").replace(/\%5F/g, "_").replace(/\%2E/g, ".").replace(/\%21/g, "!").replace(/\%7E/g, "~").replace(/\%2A/g, "*").replace(/\%27/g, "'").replace(/\%28/g, "(").replace(/\%29/g, ")")); + }catch (e) { + return null + } +} + const ffClipboard = function() {} -ffClipboard_stored = decodeURIComponent(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js +ffClipboard_stored = decodeURIEncodedMod(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js //returns an ffclipboard entry, if id does not exist, returns null ffClipboard.get =(id) => { try { From 4aac32f821b1d81f0d05e53d8915706a1825d06d Mon Sep 17 00:00:00 2001 From: NotAProton Date: Sat, 18 Dec 2021 14:01:24 +0530 Subject: [PATCH 3/3] Add backward compatibility for ffclipboard and refactor into class --- src/js/injection_script.js | 112 +++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/src/js/injection_script.js b/src/js/injection_script.js index 577d2b7d5..ca71cfee7 100644 --- a/src/js/injection_script.js +++ b/src/js/injection_script.js @@ -295,58 +295,74 @@ decodeURIEncodedMod=(s)=>{ } } - -const ffClipboard = function() {} -ffClipboard_stored = decodeURIEncodedMod(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js -//returns an ffclipboard entry, if id does not exist, returns null -ffClipboard.get =(id) => { - try { - var ffClipboardObj = JSON.parse(ffClipboard_stored) - } catch(e) { - return e - } - if (ffClipboardObj === null) { - ffClipboardObj = {} - } - if (!(id in ffClipboardObj)) { - return null - } - return ffClipboardObj[id] +//Backwards compatibility for ffclipboard +versionString = UNIVERSAL_BYPASS_EXTERNAL_VERSION + '' +let versionPatchNumber = Number(versionString.split(".").pop()) +let ffClpbrdSupported = false +if(versionPatchNumber >= 1924) { + ffClpbrdSupported = true } -//sets ffclipboard contents, if id does not exist, creates it -ffClipboard.set =(id, value) => { - try { - var ffClipboardObj = JSON.parse(ffClipboard_stored) - } catch(e) { - return e - } - - if (ffClipboardObj === null) { - ffClipboardObj = {} - } - ffClipboardObj[id] = value - let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } - window.postMessage(message, "*") //send message to content script +if (ffClpbrdSupported) { + ffClipboard_stored = decodeURIEncodedMod(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js +} else { + ffClipboard_stored = '{}' } -//deletes ffclipboard contents and frees up storage , if id does not exist, does nothing -ffClipboard.free =(id) => { - try { - var ffClipboardObj = JSON.parse(ffClipboard_stored) - } catch(e) { - return e - } - - if (ffClipboardObj === null) { - ffClipboardObj = {} - } - if (!(id in ffClipboardObj)) { - return +class ffClipboard { + constructor() { } + //returns an ffclipboard entry, if id does not exist, returns null + static get(id) { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch (e) { + return null + } + if (ffClipboardObj) { + if (ffClipboardObj[id]) { + return ffClipboardObj[id] + } else { + return null + } + } else { + return null + } + } + //sets ffclipboard contents, if id does not exist, creates it + static set(id, value) { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch (e) { + return null + } + if (ffClipboardObj) { + ffClipboardObj[id] = value + let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } + window.postMessage(message, "*") //send message to content script + ffClipboard_stored = JSON.stringify(ffClipboardObj) + } else { + return null + } + } + //deletes ffclipboard contents and frees up storage, if id does not exist, does nothing + static free(id) { + try { + var ffClipboardObj = JSON.parse(ffClipboard_stored) + } catch (e) { + return null + } + if (ffClipboardObj) { + if (ffClipboardObj[id]) { + delete ffClipboardObj[id] + let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } + window.postMessage(message, "*") + ffClipboard_stored = JSON.stringify(ffClipboardObj) + } else { + return + } + } else { + return + } } - delete ffClipboardObj[id] - let message = { type: "ffclipboardSet", text: JSON.stringify(ffClipboardObj) } - window.postMessage(message, "*") } - let navigated=false, bypassed=false, domain=location.hostname,