Add CSS for button for consistent style with SN

This commit is contained in:
ekzyis 2022-12-25 03:15:42 +01:00
parent f2fc06fe01
commit 4437416d96
1 changed files with 12 additions and 4 deletions

View File

@ -7,6 +7,7 @@
// @match https://stacker.news/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==
const headers = {
@ -48,11 +49,12 @@ const log = (msg) => console.log(`sn-translator:`, msg);
function createButton(content) {
const btn = document.createElement('button');
btn.innerText = 'Translate';
btn.innerText = 'translate';
btn.onclick = async (e) => {
const t = await translate(content.innerText, 'auto', 'en').catch(console.error);
if (t) content.innerText = t;
};
btn.classList.add('translate');
return btn;
}
@ -65,10 +67,7 @@ function addButtons() {
for (const comment of comments) {
const topBar = comment.querySelector('.item_other__qNlji');
const content = comment.querySelector('.comment_text__nHI0E');
const padding = document.createElement('span');
padding.innerText = ' ';
const btn = createButton(content);
topBar.appendChild(padding);
topBar.appendChild(btn);
}
log(`Done`);
@ -80,6 +79,15 @@ function addButtons() {
const initialSleep = 1000;
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;
log(`Current location: ${pathname}`);
addButtons();