Skip to content

Instantly share code, notes, and snippets.

@barmic
Created August 31, 2019 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barmic/e5c9fe912ff3f89c131995293726ef65 to your computer and use it in GitHub Desktop.
Save barmic/e5c9fe912ff3f89c131995293726ef65 to your computer and use it in GitHub Desktop.
DLFP scripts
// ==UserScript==
// @name DLFPNoKarma
// @namespace DLFPNoKarma
// @version 0.1
// @description https://linuxfr.org/users/peetah/journaux/plonk
// @author You
// @match https://linuxfr.org/*
// @grant none
// @run-at document-body
// ==/UserScript==
(function() {
'use strict';
let style = document.createElement("style");
style.textContent = `
.details, .vote {
display: none !important;
}
.fold {
display: contents !important;
}
.hidden {
display: contents !important;
}
.score {
display: none !important;
}
li.comment.fold > figure {
display: contents !important;
}
li.comment.fold > .content {
display: contents !important;
}
`;
document.querySelector("head").appendChild(style);
// user space
let nbVotes = document.getElementById('nb_votes');
if (nbVotes) nbVotes.parentNode.style.display = 'none';
// column notes in board
let comments = document.getElementById('my_comments');
if (comments) {
for(let myComments of comments.childNodes[1].childNodes) {
if (myComments.nodeType === Node.ELEMENT_NODE) {
myComments.removeChild(myComments.childNodes[7]);
}
}
}
// karma counter in user space
for(let userKarma of document.querySelectorAll("#user_recent_contents > ul > li")) {
if(userKarma.textContent.includes('Karma')) {
userKarma.style.display = 'none'
}
}
// remove notes
for(let score of document.querySelectorAll("span.score")) {
score.parentNode.childNodes[3].textContent='';
score.parentNode.childNodes[5].textContent='';
}
})();
// ==UserScript==
// @name DLFPlonk
// @namespace DLFPlonk
// @include https://linuxfr.org/*
// @version 1
// @grant GM_xmlhttpRequest
// ==/UserScript==
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.
//
(function() {
// unfold
document.querySelectorAll(".fold").forEach(elem => elem.classList.remove("fold"));
// nav
let comments = document.querySelectorAll(".comment");
let parsedComments = new Map();
for(let i = 0; i < comments.length; i++) {
const prevIdx = i === 0 ? comments.length - 1 : i - 1;
const nextIdx = i + 1 == comments.length ? 0 : i + 1;
parsedComments.set(comments[i].id, {up: comments[prevIdx].id, bottom: comments[nextIdx].id});
}
let ordered = Array.from(parsedComments.keys()).map(id => parseInt(id.substring("comment-".length))).sort();
for (let j = 0; j < ordered.length; j++) {
let id = "comment-" + ordered[j];
const prevIdx = j === 0 ? ordered.length - 1 : j - 1;
const nextIdx = j + 1 == ordered.length ? 0 : j + 1;
parsedComments.set(id, {...parsedComments.get(id), next: "comment-" + ordered[nextIdx], prev: "comment-" + ordered[prevIdx]});
}
let current = parsedComments.keys().next().value;
document.addEventListener('keypress', (event) => {
switch(event.key) {
case '>': current = parsedComments.get(current).bottom; break;
case '<': current = parsedComments.get(current).up; break;
case '[': current = parsedComments.get(current).prev; break;
case ']': current = parsedComments.get(current).next; break;
}
document.querySelector('#' + current).scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment