Add semicolons to EOL
This commit is contained in:
parent
315fbece44
commit
f03e98bceb
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"semi": false,
|
"semi": true,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"printWidth": 120
|
"printWidth": 120
|
||||||
}
|
}
|
|
@ -19,13 +19,13 @@ const headers = {
|
||||||
'sec-fetch-dest': 'empty',
|
'sec-fetch-dest': 'empty',
|
||||||
'sec-fetch-mode': 'cors',
|
'sec-fetch-mode': 'cors',
|
||||||
'sec-fetch-site': 'same-origin',
|
'sec-fetch-site': 'same-origin',
|
||||||
}
|
};
|
||||||
|
|
||||||
function translate(text, source, target) {
|
function translate(text, source, target) {
|
||||||
const formData = new FormData()
|
const formData = new FormData();
|
||||||
formData.append('q', text)
|
formData.append('q', text);
|
||||||
formData.append('source', source)
|
formData.append('source', source);
|
||||||
formData.append('target', target)
|
formData.append('target', target);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
GM_xmlhttpRequest({
|
GM_xmlhttpRequest({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -34,38 +34,38 @@ function translate(text, source, target) {
|
||||||
headers,
|
headers,
|
||||||
synchronous: true,
|
synchronous: true,
|
||||||
onload: function (res) {
|
onload: function (res) {
|
||||||
const body = JSON.parse(res.responseText)
|
const body = JSON.parse(res.responseText);
|
||||||
if (res.status !== 200) return reject(body)
|
if (res.status !== 200) return reject(body);
|
||||||
return resolve(body.translatedText)
|
return resolve(body.translatedText);
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||||
|
|
||||||
function addButtons() {
|
function addButtons() {
|
||||||
console.log('sn-translator: Adding button to every comment ...')
|
console.log('sn-translator: Adding button to every comment ...');
|
||||||
const commentSection = document.querySelector('.item_comments__cN57K')
|
const commentSection = document.querySelector('.item_comments__cN57K');
|
||||||
const comments = commentSection.querySelectorAll('.comment_comment__5uvl3')
|
const comments = commentSection.querySelectorAll('.comment_comment__5uvl3');
|
||||||
for (const comment of comments) {
|
for (const comment of comments) {
|
||||||
const topBar = comment.querySelector('.item_other__qNlji')
|
const topBar = comment.querySelector('.item_other__qNlji');
|
||||||
const content = comment.querySelector('.comment_text__nHI0E')
|
const content = comment.querySelector('.comment_text__nHI0E');
|
||||||
const padding = document.createElement('span')
|
const padding = document.createElement('span');
|
||||||
padding.innerText = ' '
|
padding.innerText = ' ';
|
||||||
const btn = document.createElement('button')
|
const btn = document.createElement('button');
|
||||||
btn.innerText = 'Translate'
|
btn.innerText = 'Translate';
|
||||||
btn.onclick = async (e) => {
|
btn.onclick = async (e) => {
|
||||||
const t = await translate(content.innerText, 'auto', 'en').catch(console.error)
|
const t = await translate(content.innerText, 'auto', 'en').catch(console.error);
|
||||||
if (t) content.innerText = t
|
if (t) content.innerText = t;
|
||||||
|
};
|
||||||
|
topBar.appendChild(padding);
|
||||||
|
topBar.appendChild(btn);
|
||||||
}
|
}
|
||||||
topBar.appendChild(padding)
|
console.log('Done');
|
||||||
topBar.appendChild(btn)
|
|
||||||
}
|
|
||||||
console.log('Done')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
;(async function () {
|
(async function () {
|
||||||
await sleep(1000)
|
await sleep(1000);
|
||||||
addButtons()
|
addButtons();
|
||||||
})()
|
})();
|
||||||
|
|
Loading…
Reference in New Issue