-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1100d46
commit 59e9d68
Showing
6 changed files
with
1,962 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
const ext = chrome || browser | ||
const url = ext.runtime.getURL("turnStyles.js") | ||
let core = chrome || browser | ||
let tsdb = window.localStorage.getItem("tsdb") | ||
let wipe = window.localStorage.getItem("ts-reset") | ||
let sync = core.storage ? core.storage.sync : false | ||
if (sync && wipe) window.localStorage.removeItem("ts-reset") | ||
|
||
const inject = () => { | ||
// inject url base into the window | ||
// this tells the script we're an extension | ||
const path = url.split("/turnStyles.js")[0] | ||
const base = document.createElement("script") | ||
base.textContent = `window.tsBase = "${path}"` | ||
base.type = "text/javascript" | ||
document.body.append(base) | ||
const append = js => { | ||
let file = js.indexOf(".js") > -1 | ||
let elem = document.createElement("script") | ||
if (file) elem.src = js | ||
else elem.textContent = js | ||
elem.type = "text/javascript" | ||
document.body.append(elem) | ||
} | ||
|
||
// inject the main turnStyles script | ||
const main = document.createElement("script") | ||
main.type = "text/javascript" | ||
main.src = url | ||
document.body.append(main) | ||
const inject = sync => { | ||
let file = core.runtime.getURL("turnStyles.js") | ||
let base = file.split("/turnStyles.js")[0] | ||
// inject link base into the window | ||
// tells the script we're an extension | ||
append(`window.tsBase = "${ base }"`) | ||
// if we got a backup, inject that too | ||
if (sync) append(`window.tsSync = ${ sync }`) | ||
append(file) | ||
} | ||
|
||
const sync = () => { | ||
let local = window.localStorage.getItem("tsdb") | ||
if (local) ext.storage.sync.set({ tsdb: JSON.parse(local) }) | ||
ext.storage.sync.get([ "tsdb" ], result => { | ||
let store = result.tsdb ? JSON.stringify(result.tsdb) : "" | ||
const data = document.createElement("script") | ||
data.textContent = `window.tsSync = ${ store }` | ||
data.type = "text/javascript" | ||
document.body.append(data) | ||
inject() | ||
}) | ||
const backup = () => { | ||
if (tsdb) sync.set({ tsdb: JSON.parse(tsdb) }) | ||
if (wipe) sync.remove([ "tsdb" ], db => inject()) | ||
else sync.get([ "tsdb" ], db => inject(JSON.stringify(db.tsdb || {}))) | ||
} | ||
|
||
const init = () => { | ||
if (!ext.storage) inject() | ||
else sync() | ||
return sync ? backup() : inject() | ||
} | ||
|
||
init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "turnStyles", | ||
"version": "10.6.0", | ||
"version": "10.6.1", | ||
"main": "turnStyles.js", | ||
"repository": "[email protected]:pixelcrisis/turntable-tweaks.git", | ||
"author": "pixelcrisis <[email protected]>", | ||
|