Skip to content

Instantly share code, notes, and snippets.

@floe
Last active February 11, 2022 14:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floe/166b21db1deabdec2b7e0845bd6c1151 to your computer and use it in GitHub Desktop.
Save floe/166b21db1deabdec2b7e0845bd6c1151 to your computer and use it in GitHub Desktop.
TamperMonkey script to manage the messy submission page in PrecisionConference
// ==UserScript==
// @name PCS-Janitor
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Clean out all hidden submissions from PCS
// @author @floe, based on code by @karalix
// @match https://new.precisionconference.com/submissions*
// @run-at document-end
// @grant none
// ==/UserScript==
// heavily based on https://github.com/Karalix/pcs-zen/blob/main/zenifier.js
// FIXME: currently only works if ID and Title are the first two columns
(function() {
'use strict'
function cbclick(event) {
// FIXME: ugly hack relying on column order
var id = event.target.nextSibling.textContent;
var title = event.target.parentNode.nextSibling.textContent;
if (event.target.checked) {
window.localStorage.setItem(id,title);
} else {
window.localStorage.removeItem(id);
}
}
// observe filling of the submission table
const observer = new MutationObserver((mutationList, observer) => {
for (const mutation of mutationList) {
// new node being added to <tr> tag?
if (mutation.type !== "childList") continue;
if (mutation.target.tagName !== "TR") continue;
if (mutation.addedNodes.length === 0) continue;
// is this the first child node (i.e. the first column)?
var newnode = mutation.addedNodes[0];
if (newnode.previousSibling === null) {
// yes? then throw in an extra checkbox
var checkbox = document.createElement("input");
checkbox.setAttribute("type","checkbox");
checkbox.addEventListener("click",cbclick);
// add checkbox to first column node
newnode.prepend(checkbox);
} else {
// has this id been checked before? if yes, check box & hide row
// FIXME: ugly hack relying on column order
var id = newnode.previousSibling.textContent;
var title = window.localStorage.getItem(id);
// FIXME: will fail if two papers have the same ID (unlikely, but possible)
// add checkbox to first column node
if (title !== null && newnode.textContent.includes(title)) {
newnode.previousSibling.firstChild.setAttribute("checked",true);
mutation.target.classList.add("hidden");
}
}
}
});
// look for changes to the table container div
observer.observe(document.querySelector("#user_submissions_enclosure"), { childList: true, subtree: true });
// create a "hidden" class style
var style = document.createElement("style");
var styleContent = document.createTextNode(".hidden { visibility: collapse; opacity: 0; }");
style.append(styleContent);
document.querySelector("head").append(style);
// create the show/hide button
var hidebox = document.createElement("input");
hidebox.setAttribute("type","checkbox");
hidebox.setAttribute("checked",true);
// container div to make it look nicer
var tempdiv = document.createElement("div");
tempdiv.setAttribute("style","text-align: center;");
tempdiv.append(hidebox);
tempdiv.append(document.createTextNode(" Hide obsolete submissions"));
// add or remove "hidden" style based on checkbox status
hidebox.addEventListener("click", (event) => {
for (var row of document.querySelectorAll("tr[role=row]")) {
// FIXME: ugly hack relying on column order
if (event.target.checked && row.firstChild.firstChild.checked) {
row.classList.add("hidden");
} else {
row.classList.remove("hidden");
}
}
});
document.querySelector("body").append(tempdiv);
console.log("Persistent storage granted: "+navigator.storage.persist());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment