Skip to content

Commit 839abe2

Browse files
committed
return youtube disklikes
1 parent 720293a commit 839abe2

File tree

10 files changed

+434
-120
lines changed

10 files changed

+434
-120
lines changed

index.html

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,17 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Document</title>
8-
9-
<style>
10-
.circular-progress {
11-
--size: 250px;
12-
--half-size: calc(var(--size) / 2);
13-
--stroke-width: 20px;
14-
--radius: calc((var(--size) - var(--stroke-width)) / 2);
15-
--circumference: calc(var(--radius) * pi * 2);
16-
--dash: calc((var(--progress) * var(--circumference)) / 100);
17-
}
18-
19-
.circular-progress circle {
20-
cx: var(--half-size);
21-
cy: var(--half-size);
22-
r: var(--radius);
23-
stroke-width: var(--stroke-width);
24-
fill: none;
25-
stroke-linecap: round;
26-
}
27-
28-
.circular-progress circle.bg {
29-
stroke: #ddd;
30-
}
31-
32-
.circular-progress circle.fg {
33-
transform: rotate(-90deg);
34-
transform-origin: var(--half-size) var(--half-size);
35-
stroke-dasharray: var(--dash) calc(var(--circumference) - var(--dash));
36-
transition: stroke-dasharray 0.3s linear 0s;
37-
stroke: #5394fd;
38-
}
39-
40-
@keyframes progress-animation {
41-
from {
42-
--progress: 0;
43-
}
44-
45-
to {
46-
--progress: 100;
47-
}
48-
}
49-
</style>
508
</head>
519

5210
<body>
53-
<svg width="250" height="250" viewBox="0 0 250 250" class="circular-progress" style="--progress: 90">
54-
<circle class="bg"></circle>
55-
<circle class="fg"></circle>
56-
</svg>
11+
<span>ABC</span>
12+
13+
<script type="module">
14+
import {UfsGlobal} from './scripts/content-scripts/ufs_global.js'
15+
16+
let span = document.querySelector("span");
17+
UfsGlobal.DOM.onElementTextContentChanged(span, console.log)
18+
</script>
5719
</body>
5820

5921
</html>

scripts/_test.js

Lines changed: 132 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2+
13
export default {
24
icon: "",
35
name: {
@@ -162,12 +164,95 @@ export default {
162164
},
163165

164166
contentScript: {
165-
onClick_: () => {
166-
console.log(window.location.href);
167-
},
167+
// sync element position accross all tabs
168+
_onDocumentStart: (details) => {
169+
console.log(details);
170+
171+
const div = document.createElement("div");
172+
div.id = "ufs-test";
173+
div.innerHTML = `
174+
<style>
175+
#ufs-test {
176+
position: fixed;
177+
background-color: #f1f1f1;
178+
border: 1px solid #d3d3d3;
179+
text-align: center;
180+
z-index: 999999999;
181+
top: 0;
182+
left: 0;
183+
}
184+
185+
#ufs-testheader {
186+
padding: 10px;
187+
cursor: move;
188+
z-index: 10;
189+
background-color: #2196F3;
190+
color: #fff;
191+
}
192+
</style>
193+
<div id="ufs-testheader">Click here to move</div>
194+
<p>Move</p>
195+
<p>this</p>
196+
<p>DIV</p>`;
197+
document.documentElement.appendChild(div);
198+
199+
window.ufs_test = (x, y) => {
200+
div.style.top = y + "px";
201+
div.style.left = x + "px";
202+
};
203+
204+
// Make the DIV element draggable:
205+
dragElement(div, (x, y) => {
206+
console.log(x, y);
207+
chrome.runtime.sendMessage({ action: "ufs-test", data: { x, y } });
208+
});
209+
210+
function dragElement(elmnt, onMoved) {
211+
var pos1 = 0,
212+
pos2 = 0,
213+
pos3 = 0,
214+
pos4 = 0;
215+
if (document.getElementById(elmnt.id + "header")) {
216+
// if present, the header is where you move the DIV from:
217+
document.getElementById(elmnt.id + "header").onmousedown =
218+
dragMouseDown;
219+
} else {
220+
// otherwise, move the DIV from anywhere inside the DIV:
221+
elmnt.onmousedown = dragMouseDown;
222+
}
223+
224+
function dragMouseDown(e) {
225+
e = e || window.event;
226+
e.preventDefault();
227+
// get the mouse cursor position at startup:
228+
pos3 = e.clientX;
229+
pos4 = e.clientY;
230+
document.onmouseup = closeDragElement;
231+
// call a function whenever the cursor moves:
232+
document.onmousemove = elementDrag;
233+
}
234+
235+
function elementDrag(e) {
236+
e = e || window.event;
237+
e.preventDefault();
238+
// calculate the new cursor position:
239+
pos1 = pos3 - e.clientX;
240+
pos2 = pos4 - e.clientY;
241+
pos3 = e.clientX;
242+
pos4 = e.clientY;
243+
// set the element's new position:
244+
elmnt.style.top = elmnt.offsetTop - pos2 + "px";
245+
elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
246+
}
168247

169-
onDocumentStart_: () => {
170-
console.log("____onDocumentStart");
248+
function closeDragElement() {
249+
// stop moving when mouse button is released:
250+
document.onmouseup = null;
251+
document.onmousemove = null;
252+
253+
onMoved?.(parseInt(elmnt.style.left), parseInt(elmnt.style.top));
254+
}
255+
}
171256
},
172257

173258
// text size in KB
@@ -253,8 +338,50 @@ export default {
253338
updateFavicon();
254339
},
255340
},
341+
342+
backgroundScript: {
343+
// sync element position accross all tabs
344+
_onDocumentStart: (details, context) => {
345+
const cachedPos = context.getCache("ufs-test", { x: 0, y: 0 });
346+
updatePos(details.tabId, cachedPos.x, cachedPos.y);
347+
},
348+
_runtime: {
349+
onMessage: ({ request, sender, sendResponse }, context) => {
350+
if (request.action === "ufs-test" && request.data) {
351+
context.setCache("ufs-test", request.data);
352+
chrome.tabs.query({}, (tabs) => {
353+
for (let tab of tabs) {
354+
try {
355+
updatePos(tab.id, request.data.x, request.data.y);
356+
} catch (e) {}
357+
}
358+
});
359+
}
360+
},
361+
},
362+
},
256363
};
257364

365+
function updatePos(tabId, x, y) {
366+
chrome.scripting.executeScript({
367+
target: {
368+
tabId: tabId,
369+
},
370+
func: (x, y) => {
371+
let interval = setInterval(() => {
372+
if (typeof window.ufs_test == "function") {
373+
window.ufs_test?.(x, y);
374+
clearInterval(interval);
375+
clearTimeout(timeout);
376+
}
377+
}, 100);
378+
379+
let timeout = setTimeout(() => clearInterval(interval), 10000);
380+
},
381+
args: [x, y],
382+
});
383+
}
384+
258385
const backup = () => {
259386
(() => {
260387
// modify window.fetch

scripts/background-scripts/background_script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function injectUfsGlobal(tabId, frameId, details) {
406406
func: (paths, frameId, world, url) => {
407407
paths.forEach((path) => {
408408
import(path)
409-
.then(() => console.log("Ufs import SUCCESS", frameId, world, url))
409+
// .then(() => console.log("Ufs import SUCCESS", frameId, world, url))
410410
.catch((e) =>
411411
console.error("Ufs import FAILED", frameId, world, url, e)
412412
);

scripts/chongLuaDao.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default {
110110
onMessage: ({ request, sender, sendResponse }, context) => {
111111
if (request.action === KEYS.saveCache) {
112112
saveBgCache();
113-
} else if ((request.action = KEYS.clearCache)) {
113+
} else if (request.action == KEYS.clearCache) {
114114
clearBgCache();
115115
}
116116
},

0 commit comments

Comments
 (0)