-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock-amazon-rufus.js
More file actions
142 lines (128 loc) · 4.66 KB
/
block-amazon-rufus.js
File metadata and controls
142 lines (128 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ==UserScript==
// @name Amazon: Kill Rufus + Reclaim Left Space (minimal)
// @namespace https://amazon.com/
// @author setuid@gmail.com
// @match https://www.amazon.com/*
// @match https://www.amazon.*/*
// @run-at document-start
// @updateURL https://github.com/desrod/disable-amazon-rufus-userscript/blob/main/block-amazon-rufus.js
// @downloadURL https://github.com/desrod/disable-amazon-rufus-userscript/blob/main/block-amazon-rufus.js
// @version 25.12.25.1
// @grant none
// ==/UserScript==
(function () {
"use strict";
const S = document.createElement("style");
S.textContent =
'html,body,#a-page,#pageContent,#search,#dp,main,[role="main"],#search>div,#search>div>div{margin-left:0!important;padding-left:0!important;left:0!important;transform:none!important}';
document.documentElement.appendChild(S);
const ROOT_IDS = new Set(["a-page", "pageContent", "nav-main", "search", "dp"]);
const isRootish = (e) =>
!e || !(e instanceof Element) || e.tagName === "HTML" || e.tagName === "BODY" || (e.id && ROOT_IDS.has(e.id));
const stripBody = () => {
const b = document.body;
if (!b) return;
for (const c of Array.from(b.classList)) {
const t = c.toLowerCase();
if (t.startsWith("rufus-") || t.includes("rufus")) b.classList.remove(c);
}
};
const hide = (e) => {
if (isRootish(e) || e.getAttribute("data-vm-hidden") === "1") return;
e.setAttribute("data-vm-hidden", "1");
e.style.setProperty("display", "none", "important");
e.style.setProperty("visibility", "hidden", "important");
e.style.setProperty("pointer-events", "none", "important");
};
const score = (e) => {
if (isRootish(e)) return -1;
const r = e.getBoundingClientRect();
if (!r || r.width <= 0 || r.height <= 0) return -1;
if (r.left > 30 || r.width < 240 || r.width > 750 || r.height < 240) return -1;
const cs = getComputedStyle(e);
let s = 0;
if (cs.position === "fixed" || cs.position === "sticky") s += 3;
const zi = parseInt(cs.zIndex, 10);
if (Number.isFinite(zi) && zi >= 50) s += 2;
if (r.height > r.width * 1.1) s += 1;
if (r.top < 140) s += 1;
if (r.width > innerWidth * 0.95 && r.height > innerHeight * 0.95) s -= 10;
return s;
};
const climb = (hit) => {
let best = null,
bestS = -1,
cur = hit;
for (let i = 0; i < 12 && cur && cur instanceof Element; i++) {
const s = score(cur);
if (s > bestS) (bestS = s), (best = cur);
cur = cur.parentElement;
if (cur && isRootish(cur)) break;
}
return bestS >= 3 ? best : null;
};
const killDock = () => {
stripBody();
const xs = [2, 6, 12, 18],
ys = [80, 120, 180, 260, 340, 420, 520, 620, 720];
let best = null,
bestS = -1;
for (const x of xs)
for (const y of ys) {
if (y >= innerHeight - 5) continue;
const hit = document.elementFromPoint(x, y);
if (!hit) continue;
const cand = climb(hit);
if (!cand) continue;
const s = score(cand);
if (s > bestS) (bestS = s), (best = cand);
}
if (best) hide(best);
};
const reclaim = () => {
stripBody();
const roots = [
document.getElementById("search"),
document.getElementById("dp"),
document.getElementById("pageContent"),
document.getElementById("a-page"),
document.querySelector("main"),
document.querySelector('[role="main"]'),
].filter(Boolean);
for (const e of roots) {
const r = e.getBoundingClientRect();
if (r && r.left > 50) {
e.style.setProperty("margin-left", "0", "important");
e.style.setProperty("padding-left", "0", "important");
e.style.setProperty("left", "0", "important");
e.style.setProperty("transform", "none", "important");
}
}
const cs = document.querySelectorAll("div,section,main");
for (const e of cs) {
if (isRootish(e)) continue;
const r = e.getBoundingClientRect();
if (r && r.left > 120 && r.width > innerWidth * 0.35 && r.height > innerHeight * 0.35) {
e.style.setProperty("margin-left", "0", "important");
e.style.setProperty("padding-left", "0", "important");
e.style.setProperty("left", "0", "important");
e.style.setProperty("transform", "none", "important");
break;
}
}
};
const sweep = () => {
killDock();
reclaim();
};
new MutationObserver(sweep).observe(document.documentElement, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["class", "style"],
});
sweep();
setTimeout(sweep, 200);
setTimeout(sweep, 1200);
setInterval(sweep, 2500);
})();