Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ffclipboard #260

Merged
merged 3 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 31 additions & 14 deletions src/js/content_script.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -117,19 +117,36 @@ 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

//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")+`,
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)
});
})
}
79 changes: 78 additions & 1 deletion src/js/injection_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,84 @@ 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
}
}

//Backwards compatibility for ffclipboard
versionString = UNIVERSAL_BYPASS_EXTERNAL_VERSION + ''
let versionPatchNumber = Number(versionString.split(".").pop())
let ffClpbrdSupported = false
if(versionPatchNumber >= 1924) {
ffClpbrdSupported = true
}
if (ffClpbrdSupported) {
ffClipboard_stored = decodeURIEncodedMod(ffClipboard_stored) //ffClipboard_stored is defined in content_script.js
} else {
ffClipboard_stored = '{}'
}
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
}
}
}
let navigated=false,
bypassed=false,
domain=location.hostname,
Expand Down