Skip to content

Commit

Permalink
Add backward compatibility for ffclipboard
Browse files Browse the repository at this point in the history
and refactor into class
  • Loading branch information
NotAProton committed Dec 18, 2021
1 parent bc913b7 commit 01a466d
Showing 1 changed file with 64 additions and 48 deletions.
112 changes: 64 additions & 48 deletions src/js/injection_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,58 +308,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,
Expand Down

0 comments on commit 01a466d

Please sign in to comment.