Skip to content

Commit b9d024c

Browse files
committed
tiktok standard tweaks
1 parent 392e4fd commit b9d024c

File tree

2 files changed

+92
-36
lines changed

2 files changed

+92
-36
lines changed

background.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,37 +1070,57 @@ var miscTranslations = {
10701070
};
10711071
// In background.js or a shared utility file
10721072
async function fetchWithTimeout(url, optionsOrTimeout = {}, timeoutOrHeaders = 8000) {
1073-
const isPlainObject = (value) => value && typeof value === "object" && !Array.isArray(value);
1073+
const argCount = arguments.length;
1074+
const isPlainObject = (value) => value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
1075+
const headersToObject = (value) => {
1076+
if (isPlainObject(value)) {
1077+
return { ...value };
1078+
}
1079+
if (typeof Headers !== "undefined" && value instanceof Headers) {
1080+
const obj = {};
1081+
value.forEach((val, key) => {
1082+
obj[key] = val;
1083+
});
1084+
return obj;
1085+
}
1086+
return {};
1087+
};
10741088

10751089
let timeout = 8000;
10761090
let options = {};
10771091

1078-
if (typeof optionsOrTimeout === "number") {
1079-
timeout = Number.isFinite(optionsOrTimeout) ? optionsOrTimeout : timeout;
1080-
} else if (isPlainObject(optionsOrTimeout)) {
1081-
options = { ...optionsOrTimeout };
1082-
if (isPlainObject(options.headers)) {
1083-
options.headers = { ...options.headers };
1092+
if (argCount >= 2) {
1093+
if (typeof optionsOrTimeout === "number") {
1094+
timeout = Number.isFinite(optionsOrTimeout) ? optionsOrTimeout : timeout;
1095+
} else if (isPlainObject(optionsOrTimeout)) {
1096+
options = { ...optionsOrTimeout };
1097+
if (isPlainObject(options.headers)) {
1098+
options.headers = { ...options.headers };
1099+
}
10841100
}
10851101
}
10861102

1087-
if (typeof optionsOrTimeout === "number") {
1088-
if (typeof timeoutOrHeaders === "number") {
1089-
timeout = Number.isFinite(timeoutOrHeaders) ? timeoutOrHeaders : timeout;
1090-
} else if (isPlainObject(timeoutOrHeaders)) {
1091-
options.headers = {
1092-
...(options.headers || {}),
1093-
...timeoutOrHeaders
1094-
};
1095-
}
1096-
} else {
1097-
if (typeof timeoutOrHeaders === "number") {
1098-
timeout = Number.isFinite(timeoutOrHeaders) ? timeoutOrHeaders : timeout;
1099-
} else if (isPlainObject(timeoutOrHeaders)) {
1100-
options.headers = {
1101-
...(options.headers || {}),
1102-
...timeoutOrHeaders
1103-
};
1103+
if (argCount >= 3) {
1104+
if (typeof optionsOrTimeout === "number") {
1105+
if (typeof timeoutOrHeaders === "number") {
1106+
timeout = Number.isFinite(timeoutOrHeaders) ? timeoutOrHeaders : timeout;
1107+
} else if (isPlainObject(timeoutOrHeaders)) {
1108+
const merged = {
1109+
...headersToObject(options.headers),
1110+
...timeoutOrHeaders
1111+
};
1112+
options = { ...options, headers: merged };
1113+
}
1114+
} else {
1115+
if (typeof timeoutOrHeaders === "number") {
1116+
timeout = Number.isFinite(timeoutOrHeaders) ? timeoutOrHeaders : timeout;
1117+
} else if (isPlainObject(timeoutOrHeaders)) {
1118+
const merged = {
1119+
...headersToObject(options.headers),
1120+
...timeoutOrHeaders
1121+
};
1122+
options = { ...options, headers: merged };
1123+
}
11041124
}
11051125
}
11061126

sources/tiktok.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,27 @@
963963
try {
964964
let chatNameEle = ele.querySelector("[data-e2e='message-owner-name']");
965965
if (chatNameEle) {
966-
if (chatNameEle.dataset.skip) {
967-
return;
966+
if (!chatNameEle.dataset.skip) {
967+
chatNameEle.dataset.skip = true;
968+
}
969+
let extractedName = "";
970+
try {
971+
if (typeof chatNameEle.textContent === "string") {
972+
extractedName = chatNameEle.textContent;
973+
}
974+
} catch (e) {}
975+
if (!extractedName || !extractedName.trim()) {
976+
const titleAttr = chatNameEle.getAttribute && chatNameEle.getAttribute("title");
977+
if (titleAttr) {
978+
extractedName = titleAttr;
979+
}
980+
}
981+
if ((!extractedName || !extractedName.trim()) && (typeof chatNameEle.innerText === "string")) {
982+
extractedName = chatNameEle.innerText;
983+
}
984+
if (extractedName && extractedName.trim()) {
985+
chatname = escapeHtml(extractedName.trim());
968986
}
969-
chatNameEle.dataset.skip = true;
970-
chatname = chatNameEle.textContent;
971-
chatname = escapeHtml(chatname);
972987
}
973988
} catch (e) {}
974989
try {
@@ -1172,7 +1187,10 @@
11721187
avatarCache.add(chatname, chatimg, chatbadges, membership, nameColor);
11731188
}
11741189
const compactMessage = normalizedMessage.replace(/[^a-z]/g, "");
1175-
const joinFromMessage = containsJoinKeyword(chatmessage || normalizedMessage);
1190+
const combinedJoinText = [chatmessage, normalizedMessage, ele?.textContent]
1191+
.filter(Boolean)
1192+
.join(" ");
1193+
const joinFromMessage = containsJoinKeyword(combinedJoinText);
11761194
const shareFromMessage = compactMessage.includes("share");
11771195
const followFromMessage = compactMessage.includes("follow");
11781196
const likeFromMessage = compactMessage.includes("like");
@@ -1289,12 +1307,27 @@
12891307
try {
12901308
let chatNameEle = ele.querySelector("[data-e2e='message-owner-name']");
12911309
if (chatNameEle) {
1292-
if (chatNameEle.dataset.skip) {
1293-
return;
1310+
if (!chatNameEle.dataset.skip) {
1311+
chatNameEle.dataset.skip = true;
1312+
}
1313+
let extractedName = "";
1314+
try {
1315+
if (typeof chatNameEle.textContent === "string") {
1316+
extractedName = chatNameEle.textContent;
1317+
}
1318+
} catch (e) {}
1319+
if (!extractedName || !extractedName.trim()) {
1320+
const titleAttr = chatNameEle.getAttribute && chatNameEle.getAttribute("title");
1321+
if (titleAttr) {
1322+
extractedName = titleAttr;
1323+
}
1324+
}
1325+
if ((!extractedName || !extractedName.trim()) && (typeof chatNameEle.innerText === "string")) {
1326+
extractedName = chatNameEle.innerText;
1327+
}
1328+
if (extractedName && extractedName.trim()) {
1329+
chatname = escapeHtml(extractedName.trim());
12941330
}
1295-
chatNameEle.dataset.skip = true;
1296-
chatname = chatNameEle.textContent;
1297-
chatname = escapeHtml(chatname);
12981331
}
12991332
} catch (e) {}
13001333
ele.dataset.skip = ++msgCount;
@@ -1380,7 +1413,10 @@
13801413
}
13811414
const normalizedMessage = chatmessage ? chatmessage.toLowerCase() : "";
13821415
const compactMessage = normalizedMessage.replace(/[^a-z]/g, "");
1383-
const joinFromMessage = containsJoinKeyword(chatmessage || normalizedMessage);
1416+
const combinedJoinText = [chatmessage, normalizedMessage, ele?.textContent]
1417+
.filter(Boolean)
1418+
.join(" ");
1419+
const joinFromMessage = containsJoinKeyword(combinedJoinText);
13841420
const shareFromMessage = compactMessage.includes("share");
13851421
const followFromMessage = compactMessage.includes("follow");
13861422
const likeFromMessage = compactMessage.includes("like");

0 commit comments

Comments
 (0)