-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
329 lines (292 loc) · 11.1 KB
/
index.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// ==UserScript==
// @name 「永久更新」🐹economist经济学人免费看,全部解锁,并移出了广告
// @namespace economist_hack
// @version 1.0.4
// @description 经济学人解锁所有完整内容!如果出现新的广告的情况,可以给我发邮件提醒我更新!email: kunieone@163.com 也可以在b站上关注我 @star_evan https://space.bilibili.com/1709786818 感谢大家的使用,如果感觉这个插件有用的话,可以点一个小小的赞哦👍
// @author https://github.com/kunieone
// @match https://*.economist.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant none
// @license MIT
// @esversion 6
// ==/UserScript==
// methods
function addContent(jsonData) {
let contentParagraph = "";
for (let ii = 0; ii < jsonData.length; ii++) {
switch (jsonData[ii].type) {
case "text":
contentParagraph += jsonData[ii].data;
break;
case "tag":
let attr = "";
Object.keys(jsonData[ii].attribs).forEach(function (key) {
attr += " " + key + '="' + jsonData[ii].attribs[key] + '"';
});
contentParagraph +=
"<" +
jsonData[ii].name +
attr +
">" +
addContent(jsonData[ii].children) +
"</" +
jsonData[ii].name +
">";
break;
default:
contentParagraph += "<u>" + JSON.stringify(jsonData[ii]) + "</u>";
break;
}
}
return contentParagraph;
}
// main
$(function () {
// 禁止访问该域名:
(function blocker() {
"use strict";
// Override XMLHttpRequest to block requests to pips.taboola.com
const originalXHR = window.XMLHttpRequest;
window.XMLHttpRequest = function () {
const instance = new originalXHR();
instance.open = function () {
arguments[1] = arguments[1].replace(
/pips\.taboola\.com/g,
"blocked.pips.taboola.com"
);
originalXHR.prototype.open.apply(this, arguments);
};
return instance;
};
})();
(function cleaner() {
// 选择器列表
const advertisementGroup = [
".layout-sticky-rail-advert-wrapper",
"#AdBillboard",
"#gpt-ad-slot-right-rail-r0",
"#gpt-ad-slot-regwall",
"#gpt-ad-slot-regwall",
".newsletter-signup",
"#_evidon_banner",
`[class^="adComp"]`, // 新添加一个banner广告的屏蔽
// adComponent_advert
`div[class*="adComponent_advert"]`, //20230826
`div[class*="adComponent"]`, //20230826
`div[class*="expandable-banner"]`,
"[ng-show]",
];
console.log("删除广告中");
let repeatTime = 5; // 重复扫描次数
let counter = 30; // 总的扫描次数
let intervalTime = 1000; // 初始定时间隔为1秒
let flag = false; // 标志是否删除过广告
const removeAds = () => {
advertisementGroup.forEach((item) => {
if ($(item).length) {
document.querySelectorAll(".advert").forEach((e) => e.remove());
$(item).remove();
repeatTime--;
flag = true;
}
});
counter--;
if (repeatTime <= 0 || counter <= 0 || flag === false) {
clearInterval(timer);
console.log("删除广告完成");
}
if (counter === 25) {
intervalTime = 7000; // 5秒后,扫描间隔变为7秒
}
};
// 初始执行,前5秒每秒执行一次
const timer = setInterval(removeAds, intervalTime);
// 进入「突击阶段」,每30秒重新扫描,重复5次
setTimeout(() => {
for (let i = 0; i < 5; i++) {
setTimeout(removeAds, i * 30000); // 每隔30秒执行一次
}
}, 30000);
})();
(function popper() {
// Check if the popup should be displayed based on localStorage
const popUpKey = localStorage.getItem('pop_up_key');
if (!popUpKey || popUpKey === '0') {
displayPopup();
localStorage.setItem('pop_up_key', '0');
} else {
const randomProbability = Math.random();
const popupProbability = 1 - (parseInt(popUpKey) * 0.1);
console.log({ popupProbability, randomProbability })
if (randomProbability <= popupProbability) {
displayPopup();
console.log("display!");
}
}
function displayPopup() {
const popupDiv = document.createElement('div');
popupDiv.id = 'customPopup';
popupDiv.style.display = 'none';
popupDiv.style.position = 'fixed';
popupDiv.style.top = '50%';
popupDiv.style.left = '50%';
popupDiv.style.transform = 'translate(-50%, -50%)';
popupDiv.style.backgroundColor = 'white';
popupDiv.style.padding = '20px';
popupDiv.style.border = '1px solid #ccc';
popupDiv.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
popupDiv.style.zIndex = '9999';
const closeDiv = document.createElement('div');
closeDiv.style.textAlign = 'right';
closeDiv.style.marginBottom = '10px';
const closeSpan = document.createElement('span');
closeSpan.id = 'closePopup';
closeSpan.style.cursor = 'pointer';
closeSpan.style.fontSize = '18px';
closeSpan.innerHTML = '×';
const contentDiv = document.createElement('div');
contentDiv.id = 'popupContent';
const myImageUrl1 = "https://cdnjson.com/images/2023/11/27/alipay_starevan_20231127.png";
const myImageUrl2 = "https://cdnjson.com/images/2023/11/27/WechatIMG73.jpg";
contentDiv.innerHTML = `如果这个经济学人解锁无限观看这个脚本对您有帮助,期待您的赞助!<br><img style="max-width:475px;" src="${myImageUrl2}" alt="Image">`;
closeDiv.appendChild(closeSpan);
popupDiv.appendChild(closeDiv);
popupDiv.appendChild(contentDiv);
// 在页面加载完成后执行的函数
window.onload = function () {
// 在body的最后添加弹窗的HTML
document.body.appendChild(popupDiv);
// 获取弹窗和关闭按钮的引用
const customPopup = document.getElementById('customPopup');
const closePopup = document.getElementById('closePopup');
// 设置关闭按钮的点击事件
closePopup.addEventListener('click', function () {
customPopup.style.display = 'none';
});
// 显示弹窗
customPopup.style.display = 'block';
// Set the localStorage value to 1 after displaying the popup
const popUpKey = localStorage.getItem('pop_up_key');
if (!popUpKey) {
localStorage.setItem('pop_up_key', '1');
} else {
// Increment the popup key value
localStorage.setItem('pop_up_key', (parseInt(popUpKey) + 1).toString());
}
};
}
})()
(function cracker() {
"use strict";
// Define the function to call when the element is found
function crackArticle() {
// Implement your logic here
console.log("#{debugdebug} Element found! Calling crackArticle...");
//选取文章元素
let postQuery = "#content p.article__body-text";
//选取文章内容Json
let nextData = $("#__NEXT_DATA__");
let contentParent =
// "#new-article-template > div > div:nth-child(1) > div:nth-child(3) > div section > div:nth-child(1)";
"[data-body-id]>div";
let addContentTimer = setInterval(() => {
if ($(postQuery).length <= 2) {
$(postQuery) ? $(postQuery).remove() : 0;
$("[data-body-id]>div>div:nth-child(0)").remove();
$("[data-body-id]>div>div:nth-child(1)").remove();
// 受限制模式下展示的部分文章也要删除
$(".layout-article-regwall").remove();
//重新填充内容
if (nextData.length) {
try {
const rawData = JSON.parse(nextData[0].textContent);
const contentData = rawData?.props?.pageProps?.content?.text;
// console.log(`contentData----${JSON.stringify(contentData)}`);
if (Array.isArray(contentData)) {
let figureFlag = false;
let contentParagraph = "";
for (const item of contentData) {
if (item.type === "tag") {
switch (item.name) {
case "p":
contentParagraph +=
'<p class="article__body-text">' +
addContent(item.children) +
"</p>";
break;
case "figure":
if (
item.attribs?.itemtype ===
"https://schema.org/ImageObject"
) {
for (const childItem of item.children) {
if (childItem.name === "img") {
if (figureFlag) {
contentParagraph += "</div>";
figureFlag = false;
}
contentParagraph +=
'<div class="article__body-text-image"><figure><div><img src="' +
childItem.attribs.src +
'"></div></figure>';
figureFlag = true;
}
}
}
break;
case "h2":
contentParagraph +=
"<h2>" + addContent(item.children) + "</h2>";
break;
default:
contentParagraph +=
"<" +
item.name +
">" +
addContent(item.children) +
"</" +
item.name +
">";
break;
}
}
}
if (figureFlag) {
contentParagraph += "</div>";
}
$(contentParent).append(contentParagraph);
} else {
console.log("Content data is not an array.");
}
} catch (error) {
console.error("Error parsing JSON:", error);
}
}
clearInterval(addContentTimer);
// console.log("脚本运行完毕")
}
}, 300);
}
let found = false;
let interval = setInterval(() => {
const element = document.querySelector("#tp-regwall");
if (element) {
console.log(`找到了`);
found = true;
setTimeout(() => {
crackArticle();
}, 0);
clearInterval(interval);
} else {
console.log(`没找到!`);
}
}, 10); // Check every 1 second
setTimeout(() => {
if (!found) {
clearInterval(interval); // Clear the interval if the element was not found
console.warn("#{debugdebug} Element not found within 30 seconds.");
}
}, 30000); // Stop checking after 30 seconds
})();
});