Last active
October 2, 2023 14:51
-
-
Save bagcivan/c1214bae2d15f6836d4e009cc658856d to your computer and use it in GitHub Desktop.
Enrty No
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name enrtyNo | |
// @namespace https://eksisozluk.com/biri/bagcivan | |
// @version 0.6 | |
// @description ekşi sözlük entrylerine sıra numarası verme aracı | |
// @author Tevfik Bagcivan | |
// @match https://eksisozluk1923.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=eksisozluk.com | |
// @grant nones | |
// @run-at document-end | |
// @license MIT | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const entrylerElementi = document.getElementById("entry-item-list"); | |
const entryler = Array.from(entrylerElementi.querySelectorAll("#entry-item")); | |
const currentPage = document.querySelector('.pager')?.dataset?.currentpage ?? '1'; | |
const pagerElementi = document.querySelector(".pager"); | |
const sonSayfa = parseInt(pagerElementi?.dataset?.pagecount ?? '1'); | |
const entrylerSayisi = entryler.length; | |
const sonSayfadakiEntrySayisi = entrylerSayisi % 25 || 25; | |
const sonSayfadakiIlkEntry = (sonSayfa - 1) * 25 + 1; | |
const sonSayfadakiSonEntry = (sonSayfa - 1) * 25 + sonSayfadakiEntrySayisi; | |
const toastMessage = document.createElement("div"); | |
Object.assign(toastMessage, { | |
id: "entry-link-toast", | |
style: "position: fixed; bottom: 30px; right: 30px; padding: 10px; background-color: rgba(0,0,0,0.7); color: #fff; border-radius: 5px; display: none; z-index: 1000;" | |
}); | |
document.querySelector("footer").appendChild(toastMessage); | |
const promises = entryler.map((entry, index) => { | |
const entryNo = (currentPage - 1) * 25 + (index + 1); | |
if (currentPage === sonSayfa && index >= sonSayfadakiEntrySayisi) return Promise.resolve(); | |
const entryNoElementi = document.createElement("a"); | |
Object.assign(entryNoElementi.style, { | |
"font-weight": "bold", | |
"margin-right": "1px", | |
"color": "#43A245" | |
}); | |
Object.assign(entryNoElementi, { | |
textContent: `${entryNo}.`, | |
className: "entryNo" | |
}); | |
entryNoElementi.addEventListener("click", function(event) { | |
event.preventDefault(); | |
const entryLink = entry.querySelector('.entry-date.permalink').href; | |
navigator.clipboard.writeText(entryLink) | |
.then(() => { | |
toastMessage.textContent = "Link kopyalandı: " + entryLink; | |
toastMessage.style.display = "block"; | |
setTimeout(() => { | |
toastMessage.style.display = "none"; | |
}, 1000); | |
}) | |
.catch((error) => { | |
console.error("Link kopyalanamadı: " + error); | |
}); | |
}); | |
const content = entry.querySelector("#entry-item > div.content"); | |
content.insertAdjacentElement("afterbegin", entryNoElementi); | |
const yazarNick = entry.dataset.author; | |
const profilURL = `https://eksisozluk1923.com/biri/${yazarNick}`; | |
return fetch(profilURL) | |
.then(response => response.text()) | |
.then(html => { | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(html, "text/html"); | |
try { | |
const puanBilgisi = doc.querySelector("#content-body > div.profile-top-container > p").textContent; | |
const puanElementi = document.createElement("div"); | |
Object.assign(puanElementi, { | |
className: "puan", | |
style: "font-size: 80%;", | |
textContent: puanBilgisi | |
}); | |
const yazarBilgisi = entry.querySelector("#entry-author"); | |
yazarBilgisi.appendChild(puanElementi); | |
} catch (e) { | |
const puanElementi = document.createElement("div"); | |
Object.assign(puanElementi, { | |
className: "puan", | |
style: "font-size: 80%;", | |
textContent: "karmasız (0)" | |
}); | |
const yazarBilgisi = entry.querySelector("#entry-author"); | |
yazarBilgisi.appendChild(puanElementi); | |
} | |
}) | |
.catch(console.error); | |
}); | |
Promise.all(promises).catch(console.error); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment