Add files via upload
This commit is contained in:
commit
ae4d423d94
3 changed files with 106 additions and 0 deletions
19
background.js
Normal file
19
background.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
chrome.runtime.onInstalled.addListener(() => {
|
||||
chrome.storage.local.set({ isEnabled: false });
|
||||
});
|
||||
|
||||
chrome.commands.onCommand.addListener((command) => {
|
||||
if (command === "toggle-content-script") {
|
||||
chrome.storage.local.get(['isEnabled'], (result) => {
|
||||
const isEnabled = !result.isEnabled;
|
||||
chrome.storage.local.set({ isEnabled }, () => {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
for (const tab of tabs) {
|
||||
chrome.tabs.reload(tab.id);
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
55
content-script.js
Normal file
55
content-script.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
function fixNode(node) {
|
||||
const parent = node.parentElement;
|
||||
// 親要素が存在しないなら処理しない
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
// 親要素がcssかjsだったら処理しない
|
||||
if (['style', 'script', 'noscript'].includes(parent.tagName.toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
// そもそもテキストではない場合は処理しない
|
||||
if (node.nodeType !== Node.TEXT_NODE) {
|
||||
return;
|
||||
}
|
||||
// 空のテキストは処理しない
|
||||
if (!node.textContent.trim()) {
|
||||
return;
|
||||
}
|
||||
// すでにドット化されていたら処理しない
|
||||
if (/^[\.\s]+$/g.test(node.textContent)) {
|
||||
return;
|
||||
}
|
||||
node.textContent = node.textContent.replace(/\S/g, '.');
|
||||
}
|
||||
|
||||
function fixNodeLoop(root) {
|
||||
for (const node of root.childNodes) {
|
||||
fixNodeLoop(node);
|
||||
fixNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
function launch() {
|
||||
const html = document.querySelector('html');
|
||||
|
||||
fixNodeLoop(html);
|
||||
|
||||
const observer = new MutationObserver((records, observer) => {
|
||||
for (const record of records) {
|
||||
fixNodeLoop(record.target);
|
||||
}
|
||||
});
|
||||
observer.observe(html, {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
});
|
||||
}
|
||||
|
||||
chrome.storage.local.get(['isEnabled'], (result) => {
|
||||
if (result.isEnabled) {
|
||||
launch();
|
||||
}
|
||||
});
|
32
manifest.json
Normal file
32
manifest.json
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Dotter Freeze",
|
||||
"version": "4.0",
|
||||
"description": "文字に疲れた全ての人に捧げる拡張機能です。Ctrlとドット(.)を同時押ししてテキストのない世界へダイブしよう。",
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"js": [
|
||||
"content-script.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
"commands": {
|
||||
"toggle-content-script": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Period",
|
||||
"mac": "Command+Period"
|
||||
},
|
||||
"description": "有効/無効を切り替えるZE☆"
|
||||
}
|
||||
},
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"storage"
|
||||
]
|
||||
}
|
Loading…
Add table
Reference in a new issue