From b5052ea0ef92700da00fd296a28cec4192e20a51 Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 11 Dec 2023 23:45:29 +0100 Subject: [PATCH] feat: add hnpw-extractor --- hnpw-extractor/GX.HNPW.Extractor.user.js | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 hnpw-extractor/GX.HNPW.Extractor.user.js diff --git a/hnpw-extractor/GX.HNPW.Extractor.user.js b/hnpw-extractor/GX.HNPW.Extractor.user.js new file mode 100644 index 0000000..ab05ffa --- /dev/null +++ b/hnpw-extractor/GX.HNPW.Extractor.user.js @@ -0,0 +1,77 @@ +// ==UserScript== +// @name GX.HNPW.Extractor +// @match https://vosocc.unocha.org/Report.aspx?* +// @version 1.0 +// ==/UserScript== + +// ex: https://vosocc.unocha.org/Report.aspx?page=o0t9pExuBwMwml9Wkc49cgxxxequalxxxequal +(() => { + const CONSOLE_PREFIX = "GX.HNPW.Extractor: "; + const ID_PREFIX = "gxHnpwExtractor-"; + + // + let bodyElem = document.querySelector("body"); + + function download(text){ + let link = document.createElement("a"); + let file = new Blob([text], { type: 'text/plain' }); + link.href = URL.createObjectURL(file); + link.download = "hnpw-titles.txt"; + link.click(); + URL.revokeObjectURL(link.href); + } + + function runExtract(){ + console.log(CONSOLE_PREFIX + "Begin extract()"); + let tableElem = document.querySelector("#divPublishedSessions"); + let trElemArray = tableElem.querySelectorAll("tr"); + let result = ""; + for (let trElem of trElemArray) { + console.log(trElem); + let tdElemArray = trElem.querySelectorAll("td"); + if (!tdElemArray) { continue; } + if (tdElemArray.length < 4) { continue; } + result += "* " + tdElemArray[1].textContent + "\n"; + } + + download(result); + console.log(result); + console.log(CONSOLE_PREFIX + "End extract()"); + } + + function setupTools() { + let padElem = document.createElement('div'); + padElem.id = ID_PREFIX + "pad"; + padElem.style.position = 'fixed'; + padElem.style.zIndex = "9999"; + padElem.style.top = '0'; + padElem.style.right = '0'; + padElem.style.width = '100px'; + padElem.style.height = '50px'; + padElem.style.border = '1px solid black'; + padElem.style.backgroundColor = 'rgba(0,0,0,0.5)'; + padElem.style.display = "flex"; + padElem.style.justifyContent = "center"; + padElem.style.alignItems = "center"; + + let buttonElem = document.createElement("input"); + buttonElem.value = "Extract"; + buttonElem.type = "button"; + buttonElem.addEventListener("click", runExtract) + + // Insertion des éléments dans le body + padElem.appendChild(buttonElem); + bodyElem.appendChild(padElem); + } + + function initialize() { + console.log(CONSOLE_PREFIX + "Begin setup()"); + let padElem = document.querySelector('#' + ID_PREFIX + "pad"); + if (!padElem) { + setupTools(); + } + console.log(CONSOLE_PREFIX + "End setup()"); + } + + initialize(); +})(); \ No newline at end of file