Skip to content

Commit 8ca4401

Browse files
committed
done ajax hook + apply to old scripts
1 parent 23dccfd commit 8ca4401

File tree

6 files changed

+64
-97
lines changed

6 files changed

+64
-97
lines changed

scripts/fb_blockSeenStory.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,15 @@ export default {
2525
onBeforeSend: ({ method, url, async, user, password }, dataSend) => {
2626
if (
2727
method === "POST" &&
28-
dataSend?.toString?.includes("storiesUpdateSeenStateMutation")
28+
dataSend?.toString?.()?.includes?.("storiesUpdateSeenStateMutation")
2929
) {
30+
UfsGlobal.DOM.notify({
31+
msg: "Useful script: facebook story seen BLOCKED",
32+
});
3033
return CANCEL_XHR;
3134
}
3235
},
3336
});
34-
// const e = window.XMLHttpRequest;
35-
// window.XMLHttpRequest = new Proxy(e, {
36-
// construct(o, r) {
37-
// const instance = new o(...r),
38-
// open = instance.open;
39-
// instance.open = function (method, url, m, y, f) {
40-
// return (
41-
// (this._method = method),
42-
// (this._url = url),
43-
// open.apply(this, arguments)
44-
// );
45-
// };
46-
// const send = instance.send;
47-
// return (
48-
// (instance.send = function (data) {
49-
// if (
50-
// !(
51-
// this._method === "POST" &&
52-
// data?.toString().includes("storiesUpdateSeenStateMutation")
53-
// )
54-
// )
55-
// return send.apply(this, arguments);
56-
// else {
57-
// UfsGlobal.DOM.notify({
58-
// msg: "Useful script: facebook story seen BLOCKED",
59-
// });
60-
// }
61-
// }),
62-
// instance
63-
// );
64-
// },
65-
// });
6637
},
6738
},
6839
};

scripts/fb_getPostReactionCount.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UfsGlobal } from "./content-scripts/ufs_global.js";
22
import { fetchGraphQl, getFbdtsg } from "./fb_GLOBAL.js";
3+
import { hookXHR } from "./libs/ajax-hook/index.js";
34

45
export default {
56
icon: '<i class="fa-solid fa-thumbs-up fa-lg"></i>',
@@ -93,34 +94,32 @@ export default {
9394
closeAfter(10000);
9495
};
9596

96-
const originalXMLSend = XMLHttpRequest.prototype.send;
97-
XMLHttpRequest.prototype.send = function () {
98-
let s = arguments[0]?.toString() || "";
99-
if (
100-
s.includes("CometUFIReactionsCountTooltipContentQuery") ||
101-
s.includes("CometUFIReactionIconTooltipContentQuery")
102-
) {
103-
const originalReady = this.onreadystatechange;
104-
this.onreadystatechange = function () {
105-
if (this.readyState == 4) {
106-
try {
107-
const json = JSON.parse(this.responseText);
108-
if (
109-
json?.data?.feedback?.reaction_display_config
110-
?.reaction_display_strategy == "HIDE_COUNTS"
111-
) {
112-
const id = json.data.feedback.id;
113-
getTotalPostReactionCount(id);
114-
}
115-
} catch (err) {
116-
console.log(err);
97+
hookXHR({
98+
onAfterSend: (
99+
{ method, url, async, user, password },
100+
dataSend,
101+
response
102+
) => {
103+
let str = dataSend?.toString?.() || "";
104+
if (
105+
str.includes("CometUFIReactionsCountTooltipContentQuery") ||
106+
str.includes("CometUFIReactionIconTooltipContentQuery")
107+
) {
108+
try {
109+
const json = JSON.parse(response);
110+
if (
111+
json?.data?.feedback?.reaction_display_config
112+
?.reaction_display_strategy == "HIDE_COUNTS"
113+
) {
114+
const id = json.data.feedback.id;
115+
getTotalPostReactionCount(id);
117116
}
117+
} catch (err) {
118+
console.log(err);
118119
}
119-
originalReady.apply(this, arguments);
120-
};
121-
}
122-
originalXMLSend.apply(this, arguments);
123-
};
120+
}
121+
},
122+
});
124123
},
125124
},
126125
};

scripts/fb_stopNewFeed.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { UfsGlobal } from "./content-scripts/ufs_global.js";
21
import { BADGES } from "./helpers/badge.js";
2+
import { UfsGlobal } from "./content-scripts/ufs_global.js";
3+
import { CANCEL_XHR, hookXHR } from "./libs/ajax-hook/index.js";
34

45
export default {
56
icon: '<i class="fa-solid fa-ban fa-lg"></i>',
@@ -72,27 +73,26 @@ function stopNewFeed() {
7273
};
7374

7475
let enabled = true;
75-
const originalXMLSend = XMLHttpRequest.prototype.send;
76-
XMLHttpRequest.prototype.send = function () {
77-
let s = arguments[0]?.toString() || "";
76+
hookXHR({
77+
onBeforeSend: ({ method, url, async, user, password }, dataSend) => {
78+
let s = dataSend?.toString() || "";
7879

79-
let inBlackList = false;
80-
for (const [key, value] of Object.entries(blackList)) {
81-
if (value.find((item) => s.includes(item))) {
82-
inBlackList = key;
83-
break;
80+
let inBlackList = false;
81+
for (const [key, value] of Object.entries(blackList)) {
82+
if (value.find((item) => s.includes(item))) {
83+
inBlackList = key;
84+
break;
85+
}
8486
}
85-
}
8687

87-
if (enabled && inBlackList) {
88-
UfsGlobal.DOM.notify({
89-
msg: "Useful-script: Stopped new feed facebook '" + inBlackList + "'",
90-
});
91-
console.log(arguments);
92-
} else {
93-
originalXMLSend.apply(this, arguments);
94-
}
95-
};
88+
if (enabled && inBlackList) {
89+
UfsGlobal.DOM.notify({
90+
msg: "Useful-script: Stopped new feed facebook '" + inBlackList + "'",
91+
});
92+
return CANCEL_XHR;
93+
}
94+
},
95+
});
9696

9797
UfsGlobal.DOM.notify({
9898
msg: "Useful-script: ENABLED Stop new feed facebook",

scripts/insta_anonymousStoryViewer.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2+
import { CANCEL_XHR, hookXHR } from "./libs/ajax-hook/index.js";
23

34
export default {
45
icon: '<i class="fa-solid fa-eye-slash fa-lg"></i>',
@@ -21,19 +22,17 @@ export default {
2122

2223
pageScript: {
2324
onDocumentStart: () => {
24-
(function () {
25-
var originalXMLSend = XMLHttpRequest.prototype.send;
26-
XMLHttpRequest.prototype.send = function () {
27-
let s = arguments[0]?.toString() || "";
25+
hookXHR({
26+
onBeforeSend: ({ method, url, async, user, password }, dataSend) => {
27+
let s = dataSend?.toString() || "";
2828
if (s.includes("viewSeenAt") || s.includes("SeenMutation")) {
2929
UfsGlobal.DOM.notify({
3030
msg: "Useful-script: Blocked story view tracking",
3131
});
32-
} else {
33-
originalXMLSend.apply(this, arguments);
32+
return CANCEL_XHR;
3433
}
35-
};
36-
})();
34+
},
35+
});
3736
},
3837

3938
onDocumentEnd: () => {

scripts/libs/ajax-hook/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const cancelKey = "_ufs_cancel_";
33
function _hook(configs = []) {
44
const unsubFn = [];
55
for (let { fn, arr } of configs) {
6+
if (typeof fn !== "function" || !Array.isArray(arr)) continue;
67
let id = randId();
78
arr.push({ fn, id });
89
unsubFn.push(() => {
@@ -84,29 +85,26 @@ function initXhr() {
8485
window.XMLHttpRequest = new Proxy(orig, {
8586
construct(o, r) {
8687
const instance = new o(...r);
87-
8888
let p;
8989

9090
const open = instance.open;
9191
instance.open = function (method, url, async, user, password) {
92-
this._method = method;
93-
this._url = url;
94-
9592
p = { method, url, async, user, password };
9693
for (let { fn } of onBeforeOpenXHRFn) p = fn?.(p) || p;
9794
if (p?.[cancelKey]) return;
9895

99-
return open.apply(this, [p.mr]);
96+
return open.apply(this, [p.method, p.url, p.async, p.user, p.password]);
10097
};
10198

10299
const send = instance.send;
103-
instance.send = function (data) {
104-
for (let { fn } of onBeforeSendXHRFn) data = fn?.(p, data) || data;
105-
if (data?.[cancelKey]) return;
100+
instance.send = function (dataSend) {
101+
for (let { fn } of onBeforeSendXHRFn)
102+
dataSend = fn?.(p, dataSend) || dataSend;
103+
if (dataSend?.[cancelKey]) return;
106104

107105
instance.addEventListener("load", function () {
108106
for (let { fn } of onAfterSendXHRFn)
109-
fn?.(p, data, instance.responseText);
107+
fn?.(p, dataSend, instance.response);
110108
});
111109

112110
return send.apply(this, arguments);

scripts/soundcloud_downloadMusic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
par.prepend(downloadBtn);
4949
}
5050
}
51-
}, [1000]);
51+
}, 1000);
5252

5353
let clientId;
5454
window.ufs_soundcloud_allData = new Map();
@@ -66,7 +66,7 @@ export default {
6666
);
6767
const json = await res.json();
6868

69-
if (json && json.id) {
69+
if (json?.id) {
7070
// save media
7171
if (json.media) {
7272
window.ufs_soundcloud_allData.set(json.id, json);

0 commit comments

Comments
 (0)