Add CSS for button for consistent style with SN
This commit is contained in:
parent
f2fc06fe01
commit
4437416d96
@ -7,6 +7,7 @@
|
|||||||
// @match https://stacker.news/*
|
// @match https://stacker.news/*
|
||||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
|
// @grant GM_addStyle
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
@ -48,11 +49,12 @@ const log = (msg) => console.log(`sn-translator:`, msg);
|
|||||||
|
|
||||||
function createButton(content) {
|
function createButton(content) {
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
btn.classList.add('translate');
|
||||||
return btn;
|
return btn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +67,7 @@ function addButtons() {
|
|||||||
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');
|
|
||||||
padding.innerText = ' ';
|
|
||||||
const btn = createButton(content);
|
const btn = createButton(content);
|
||||||
topBar.appendChild(padding);
|
|
||||||
topBar.appendChild(btn);
|
topBar.appendChild(btn);
|
||||||
}
|
}
|
||||||
log(`Done`);
|
log(`Done`);
|
||||||
@ -80,6 +79,15 @@ function addButtons() {
|
|||||||
const initialSleep = 1000;
|
const initialSleep = 1000;
|
||||||
await sleep(initialSleep);
|
await sleep(initialSleep);
|
||||||
|
|
||||||
|
GM_addStyle(`
|
||||||
|
.translate {
|
||||||
|
color: var(--theme-grey);
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
background: rgba(0,0,0,0);
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
let pathname = window.location.pathname;
|
let pathname = window.location.pathname;
|
||||||
log(`Current location: ${pathname}`);
|
log(`Current location: ${pathname}`);
|
||||||
addButtons();
|
addButtons();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user