Prefix logs with 'sn-translator'

This commit is contained in:
ekzyis 2022-12-25 02:57:20 +01:00
parent fb25d27e0d
commit 6f1a38bb7d
1 changed files with 7 additions and 4 deletions

View File

@ -44,10 +44,13 @@ function translate(text, source, target) {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const log = (msg) => console.log(`sn-translator: `, msg);
function addButtons() {
console.log('sn-translator: Adding button to every comment ...');
const commentSection = document.querySelector('.item_comments__cN57K');
const comments = commentSection.querySelectorAll('.comment_comment__5uvl3');
log(`Found ${comments.length} comment(s)`);
log(`Adding translate button to every comment ...`);
for (const comment of comments) {
const topBar = comment.querySelector('.item_other__qNlji');
const content = comment.querySelector('.comment_text__nHI0E');
@ -62,7 +65,7 @@ function addButtons() {
topBar.appendChild(padding);
topBar.appendChild(btn);
}
console.log('Done');
log(`Done`);
}
(async function () {
@ -72,14 +75,14 @@ function addButtons() {
await sleep(initialSleep);
let pathname = window.location.pathname;
console.log(`Current location: ${pathname}`);
log(`Current location: ${pathname}`);
addButtons();
// Check if URL changed and rerun script
const scriptInterval = 1000;
setInterval(() => {
if (window.location.pathname !== pathname) {
pathname = window.location.pathname;
console.log(`New location detected: ${pathname}`);
log(`New location detected: ${pathname}`);
addButtons();
}
}, scriptInterval);