-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
80 additions
and
51 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
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,21 +1,18 @@ | ||
// 获取选择的语言 | ||
const lang = document.querySelector('#lang'); | ||
// 保存选择的语言 | ||
lang.addEventListener('change', (e) => { | ||
console.log(e.target.value); | ||
// 获取选择的语言 | ||
const language = e.target.value; | ||
// 保存选择的语言 | ||
chrome.storage.sync.set({language}, () => { | ||
console.log('保存成功'); | ||
// chrome.scripting.insertCSS({ | ||
// files: ['include/theme/stackoverflow-light.css'] | ||
// }); | ||
}); | ||
}); | ||
// 获取选择的语言 | ||
const theme = document.querySelector("#theme"); | ||
// 保存选择的语言 | ||
theme.addEventListener("change", (e) => { | ||
console.log(e.target.value); | ||
// 获取选择的语言 | ||
const chooseTheme = e.target.value; | ||
// 保存选择的语言 | ||
chrome.storage.sync.set({ chooseTheme }, () => { | ||
console.log("保存成功"); | ||
}); | ||
}); | ||
|
||
// 获取保存的语言 | ||
chrome.storage.sync.get(['language'], (result) => { | ||
// 设置选择的语言 | ||
lang.value = result.language; | ||
}); | ||
// 获取保存的语言 | ||
chrome.storage.sync.get(["chooseTheme"], (result) => { | ||
// 设置选择的语言 | ||
theme.value = result.chooseTheme; | ||
}); |
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,11 +1,58 @@ | ||
chrome.storage.onChanged.addListener((changes,areaName) => { | ||
console.log("storage change",changes,areaName); | ||
} | ||
) | ||
chrome.storage.onChanged.addListener((changes, areaName) => { | ||
if (changes.chooseTheme.oldValue) { | ||
chrome.scripting.unregisterContentScripts({ | ||
ids: [changes.chooseTheme.oldValue], | ||
}); | ||
} | ||
|
||
if (changes.chooseTheme.newValue) { | ||
const new_flomo_theme = { | ||
id: changes.chooseTheme.newValue, | ||
matches: ["https://v.flomoapp.com/*", "https://flomoapp.com/*"], | ||
css: ["include/theme/" + changes.chooseTheme.newValue], | ||
runAt: "document_end", | ||
}; | ||
chrome.scripting.registerContentScripts([new_flomo_theme]); | ||
|
||
// 使新的css生效 | ||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { | ||
// 注入新的内容脚本,如果当前页面是chrome:// 则不注入 | ||
if (tabs[0].url.indexOf("chrome://") > -1) { | ||
return; | ||
} | ||
console.log("注入新的css" + tabs[0].id); | ||
chrome.scripting.insertCSS({ | ||
target: { | ||
tabId: tabs[0].id, | ||
}, | ||
files: ["include/theme/" + changes.chooseTheme.newValue], | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
chrome.tabs.onCreated.addListener( | ||
(tab)=>{ | ||
console.log("tab created",tab); | ||
|
||
const DEFAULT_THEME = "stackoverflow-dark.css"; | ||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.storage.sync.set({ chooseTheme: DEFAULT_THEME }, () => { | ||
console.log("保存成功"); | ||
}); | ||
}); | ||
|
||
function getTheme() { | ||
// 获取当前主题 | ||
chrome.storage.sync.get("chooseTheme", (result) => { | ||
if (result.chooseTheme) { | ||
console.log("当前主题为", result.chooseTheme); | ||
DEFAULT_THEME = result.chooseTheme; | ||
} | ||
) | ||
}); | ||
return DEFAULT_THEME; | ||
} | ||
|
||
const flomo_content_script = { | ||
id: "flomo_content_script", | ||
matches: ["https://v.flomoapp.com/*", "https://flomoapp.com/*"], | ||
js: ["scripts/content.js", "include/highlight.min.js"], | ||
runAt: "document_end", | ||
}; | ||
chrome.scripting.registerContentScripts([flomo_content_script]); |