Last active
January 19, 2023 16:13
-
-
Save Konfuze/b630ee96b857d229182386973b8ee396 to your computer and use it in GitHub Desktop.
Show key name in search results
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 New Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://weblate.team.practicum.com/search/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=practicum.com | |
// @grant none | |
// ==/UserScript== | |
(async function() { | |
'use strict'; | |
const getCheckSum = (url) => { | |
return (new URL(url)).searchParams.get('checksum') | |
} | |
const isSearchPage = document.querySelector('.result-page-form') | |
if (!isSearchPage) { | |
return; | |
} | |
const cache = {} | |
const rows = document.querySelectorAll('.unit-listing-body tr'); | |
for (let row of rows) { | |
const link = row.querySelector('td:last-child a') | |
if (!link) { | |
return | |
} | |
const keyColumn = document.createElement('td'); | |
keyColumn.innerText = 'loading...'; | |
keyColumn.style.minWidth = '200px' | |
row.append(keyColumn); | |
let keyName = cache[getCheckSum(link.href)] | |
if (!keyName) { | |
const html = await (await fetch(link.href)).text() | |
const fetchedDocument = document.createElement('div') | |
fetchedDocument.innerHTML = html; | |
keyName = | |
fetchedDocument.querySelector('.source-language-group .wrap-simple')?.innerText || | |
fetchedDocument.querySelector('.list-group-item.sidebar-button .wrap-text')?.innerText || | |
'-'; | |
cache[getCheckSum(link.href)] = keyName; | |
} | |
keyColumn.innerText = keyName; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment