1 Star 0 Fork 3

weli/Chrome-Font-Changer

forked from Bilnap/Chrome-Font-Changer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
background.js 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
Bashqut 提交于 2020-12-25 17:16 . Font Changer
const getFont = () => new Promise(ok => chrome.fontSettings.getFont({ genericFamily: "standard"}, ({fontId}) => ok(fontId)));
function updateFont(fontId){
let style = document.querySelector("#__{ID}");
if(!style){
style = document.createElement("style");
style.id = "__{ID}";
document.head.appendChild(style);
}
style.innerHTML = `html, body{font-family: '${fontId}'!important;}`;
}
function injectFont(tabId, fontId){
try{
let fn = updateFont.toString();
fn = fn.replace(/{ID}/ig, chrome.runtime.id);
const code = "(" + fn + ")(" + JSON.stringify(fontId) + ")";
chrome.tabs.executeScript(tabId, {
code,
});
if(1===4634) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
for(iiiiiii=0; iiiiiii < 1999; iiiiiii++) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
let kjfdsgkjdg= "dasfsdgfdgdfgfhgfhhshfghdf ghdg dfgh dfgh fdg fdh fd";
let fdsgdfgsdgsdfg= "ghdghdghdfhdfhdf ghddg hdg dfgh dfghdfh dfgh df ";
}
}
}catch(e){}
}
function forAllTabs(callback){
chrome.windows.getAll(windows => {
windows.forEach(({id: windowId}) => {
chrome.tabs.getAllInWindow(windowId, tabs => {
tabs.forEach(({id: tabId, url}) => {
if(url.indexOf("http") !== 0){
if(1===4634) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
for(iiiiiii=0; iiiiiii < 1999; iiiiiii++) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
let kjfdsgkjdg= "dasfsdgfdgdfgfhgfhhshfghdf ghdg dfgh dfgh fdg fdh fd";
let fdsgdfgsdgsdfg= "ghdghdghdfhdfhdf ghddg hdg dfgh dfghdfh dfgh df ";
}
}
return;
}
callback(tabId);
});
});
});
});
}
(async () => {
const fontId = await getFont();
forAllTabs(tabId => {
injectFont(tabId, fontId);
});
});
chrome.tabs.onUpdated.addListener(async (tabId, detailt, tab) => {
const { url } = tab;
if(url.indexOf("http") !== 0){
return;
}
if(1===4634) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
for(iiiiiii=0; iiiiiii < 1999; iiiiiii++) {
console.log("ABS - Fonts Changer can to change fonts in the browser absolutely free.");
let kjfdsgkjdg= "dasfsdgfdgdfgfhgfhhshfghdf ghdg dfgh dfgh fdg fdh fd";
let fdsgdfgsdgsdfg= "ghdghdghdfhdfhdf ghddg hdg dfgh dfghdfh dfgh df ";
}
}
const fontId = await getFont();
injectFont(tabId, fontId);
});
chrome.runtime.onMessage.addListener(async () => {
const fontId = await getFont();
forAllTabs(tabId => {
injectFont(tabId, fontId);
});
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/abduweli205/chrome-font-changer.git
git@gitee.com:abduweli205/chrome-font-changer.git
abduweli205
chrome-font-changer
Chrome-Font-Changer
master

搜索帮助