Skip to content

Commit 72983e4

Browse files
committed
add: initial version
1 parent 0c60fe9 commit 72983e4

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

128.png

13.7 KB
Loading

32.png

2.25 KB
Loading

48.png

3.53 KB
Loading

content_scripts.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
// get initial val
3+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
4+
chrome.tabs.sendMessage(tabs[0].id, { cmd: "check" }, function (msg) {
5+
if (msg === "on") {
6+
document.getElementById("toggle-val").checked = true;
7+
} else {
8+
document.getElementById("toggle-val").checked = false;
9+
}
10+
});
11+
});
12+
13+
// add event listener at toggle
14+
document.getElementById("toggle-val").addEventListener("change", function () {
15+
if (this.checked) {
16+
// on
17+
localStorage.setItem("enableBluebird", "on");
18+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
19+
chrome.tabs.sendMessage(
20+
tabs[0].id,
21+
{ cmd: "replace", replace: true },
22+
function (msg) {}
23+
);
24+
});
25+
} else {
26+
// off
27+
localStorage.setItem("enableBluebird", "off");
28+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
29+
chrome.tabs.sendMessage(
30+
tabs[0].id,
31+
{ cmd: "replace", replace: false },
32+
function (msg) {}
33+
);
34+
});
35+
}
36+
});
37+
});

editor.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const newLogo = `
2+
<svg
3+
viewBox="0 0 24 24"
4+
aria-hidden="true"
5+
class="r-16ek5rh r-4qtqp9 r-yyyyoo r-16y2uox r-8kz0gk r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-lrsllp"
6+
>
7+
<g>
8+
<path d="M14.258 10.152L23.176 0h-2.113l-7.747 8.813L7.133 0H0l9.352 13.328L0 23.973h2.113l8.176-9.309 6.531 9.309h7.133zm-2.895 3.293l-.949-1.328L2.875 1.56h3.246l6.086 8.523.945 1.328 7.91 11.078h-3.246zm0 0"></path>
9+
</g>
10+
</svg>
11+
`;
12+
13+
const oldLogo = `
14+
<svg
15+
viewBox="0 0 24 24"
16+
aria-hidden="true"
17+
class="r-16ek5rh r-4qtqp9 r-yyyyoo r-16y2uox r-8kz0gk r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-lrsllp"
18+
style="color: rgba(29,155,240,1.00)"
19+
>
20+
<g>
21+
<path d="M23.643 4.937c-.835.37-1.732.62-2.675.733.962-.576 1.7-1.49 2.048-2.578-.9.534-1.897.922-2.958 1.13-.85-.904-2.06-1.47-3.4-1.47-2.572 0-4.658 2.086-4.658 4.66 0 .364.042.718.12 1.06-3.873-.195-7.304-2.05-9.602-4.868-.4.69-.63 1.49-.63 2.342 0 1.616.823 3.043 2.072 3.878-.764-.025-1.482-.234-2.11-.583v.06c0 2.257 1.605 4.14 3.737 4.568-.392.106-.803.162-1.227.162-.3 0-.593-.028-.877-.082.593 1.85 2.313 3.198 4.352 3.234-1.595 1.25-3.604 1.995-5.786 1.995-.376 0-.747-.022-1.112-.065 2.062 1.323 4.51 2.093 7.14 2.093 8.57 0 13.255-7.098 13.255-13.254 0-.2-.005-.402-.014-.602.91-.658 1.7-1.477 2.323-2.41z"></path>
22+
</g>
23+
</svg>
24+
`;
25+
26+
window.addEventListener("load", function () {
27+
var state = localStorage.getItem("enableBluebird");
28+
if (!state) {
29+
state = "off";
30+
this.localStorage.setItem("enableBluebird", "off");
31+
}
32+
33+
if (state === "on") {
34+
const jsInitCheckTimer = setInterval(pageLoaded, 1);
35+
function pageLoaded() {
36+
var logoDOM = document.getElementsByXPath("//h1/a/div");
37+
if (logoDOM.length > 0) {
38+
logoDOM[0].innerHTML = oldLogo;
39+
clearInterval(jsInitCheckTimer);
40+
}
41+
}
42+
}
43+
});
44+
45+
document.getElementsByXPath = function (expression, parentElement) {
46+
var r = [];
47+
var x = document.evaluate(
48+
expression,
49+
parentElement || document,
50+
null,
51+
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
52+
null
53+
);
54+
for (var i = 0, l = x.snapshotLength; i < l; i++) {
55+
r.push(x.snapshotItem(i));
56+
}
57+
return r;
58+
};
59+
60+
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
61+
if (msg.cmd === "check") {
62+
// check init state
63+
var state = localStorage.getItem("enableBluebird");
64+
if (!state) {
65+
state = "off";
66+
localStorage.setItem("enableBluebird", "off");
67+
}
68+
sendResponse(state);
69+
} else if (msg.cmd == "replace") {
70+
// run replace
71+
var logoDOM = document.getElementsByXPath("//h1/a/div");
72+
if (logoDOM.length === 0) {
73+
sendResponse(undefined);
74+
} else {
75+
if (msg.replace) {
76+
logoDOM[0].innerHTML = oldLogo;
77+
localStorage.setItem("enableBluebird", "on");
78+
} else {
79+
logoDOM[0].innerHTML = newLogo;
80+
localStorage.setItem("enableBluebird", "off");
81+
}
82+
}
83+
sendResponse(undefined);
84+
}
85+
});

manifest.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Blue Bird Replacer",
4+
"description": "ブラウザ版のロゴを青い鳥に変更します。",
5+
"version": "1.0",
6+
"icons": {
7+
"32": "32.png",
8+
"48": "48.png",
9+
"128": "128.png"
10+
},
11+
"content_scripts": [
12+
{
13+
"matches": [
14+
"https://twitter.com/*"
15+
],
16+
"js": [
17+
"editor.js"
18+
],
19+
"run_at": "document_end"
20+
}
21+
],
22+
"permissions": [
23+
"storage"
24+
],
25+
"action": {
26+
"default_popup": "popup.html"
27+
}
28+
}

popup.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
body {
2+
margin-top: 50px;
3+
width: 250px;
4+
text-align: center;
5+
}
6+
7+
.toggle_input {
8+
position: absolute;
9+
left: 0;
10+
top: 0;
11+
width: 100%;
12+
height: 100%;
13+
z-index: 5;
14+
opacity: 0;
15+
cursor: pointer;
16+
}
17+
18+
.toggle_label {
19+
width: 75px;
20+
height: 35px;
21+
background: #ccc;
22+
position: relative;
23+
display: inline-block;
24+
border-radius: 40px;
25+
transition: 0.4s;
26+
box-sizing: border-box;
27+
}
28+
29+
.toggle_label:after {
30+
content: "";
31+
position: absolute;
32+
width: 35px;
33+
height: 35px;
34+
border-radius: 100%;
35+
left: 0;
36+
top: 0;
37+
z-index: 2;
38+
background: #fff;
39+
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
40+
transition: 0.4s;
41+
}
42+
43+
.toggle_input:checked + .toggle_label {
44+
background-color: #4bd865;
45+
}
46+
47+
.toggle_input:checked + .toggle_label:after {
48+
left: 40px;
49+
}
50+
51+
.toggle_button {
52+
position: relative;
53+
width: 75px;
54+
height: 35px;
55+
margin: auto;
56+
}

popup.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="jp">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Bluebird Replacer</title>
6+
<link rel="stylesheet" type="text/css" href="popup.css" />
7+
</head>
8+
<body>
9+
<h1>Bluebird Replacer</h1>
10+
<h2>Enable Replace</h1>
11+
<div class="toggle_button">
12+
<input id="toggle-val" class="toggle_input" type="checkbox" />
13+
<label for="toggle" class="toggle_label" />
14+
</div>
15+
16+
<script src="content_scripts.js"></script>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)