Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Always show post counts by ID - 8chan.moe
- // @namespace Violentmonkey Scripts
- // @match https://*.8chan.moe/*
- // @grant GM_addStyle
- // @run-at document-end
- // ==/UserScript==
- if (typeof posting === "undefined") return;
- if (typeof GM_addStyle === 'undefined') {
- function GM_addStyle(css) {
- 'use strict';
- const style = document.createElement('style');
- style.textContent = css;
- document.head.appendChild(style);
- return style;
- }
- }
- GM_addStyle(`
- .labelId.dark-post-count {
- color: #000c;
- }
- .labelId.dark-post-count::after {
- color: #000c;
- border-left: 1px solid #000a;
- }
- .labelId.light-post-count {
- color: #fffd;
- }
- .labelId.light-post-count::after {
- color: #fffd;
- border-left: 1px solid #fffa;
- }
- .labelId::after {
- content: attr(data-posts-by-this-id);
- margin-left: 0.4em;
- padding: 1px 4px;
- }
- .labelId {
- background-image: none;
- paint-order: stroke fill;
- padding: 1px 0px 1px 4px; !important;
- text-shadow: none;
- }
- `);
- function linearize(c) {
- return c <= 0.040449936 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
- }
- function toneFromRgb(red, green, blue) {
- const redL = linearize(red), greenL = linearize(green), blueL = linearize(blue);
- const y = (0.2126 * redL + 0.7152 * greenL + 0.0722 * blueL);
- return y > 0.00885645 ? 116.0 * Math.pow(y, 1.0 / 3.0) - 16.0 : 903.296296 * y;
- }
- function styleIdText(label) {
- const hex = label.innerText;
- const r = parseInt(hex.substring(0, 2), 16) / 255;
- const g = parseInt(hex.substring(2, 4), 16) / 255;
- const b = parseInt(hex.substring(4, 6), 16) / 255;
- label.classList.add(toneFromRgb(r, g, b) >= 57 ? "dark-post-count" : "light-post-count");
- }
- // Process all the posts that was rendered before this script runs.
- for (const [id, posts] of Object.entries(posting.idsRelation)) {
- for (const post of posts) {
- const label = post.querySelector(".labelId");
- // Remove these listeners because our hook doesn't work during page load (wtf Lynxchan?)
- label.onmouseover = null;
- label.onmouseout = null;
- // Set the post count.
- label.setAttribute("data-posts-by-this-id", posts.length);
- styleIdText(label);
- }
- }
- // This was pasted straight from 8chan.moe source code.
- posting.processIdLabel = function(label) {
- if (!label) return;
- const id = label.textContent;
- const postsOfThisId = posting.idsRelation[id] || [];
- const innerPost = label.closest(".innerPost, .innerOP");
- if (innerPost.classList.contains("clone")) {
- label.setAttribute("data-posts-by-this-id", postsOfThisId.length);
- } else {
- posting.idsRelation[id] = postsOfThisId;
- postsOfThisId.push(innerPost);
- // Update the count for all the .labelID elements of this ID.
- for (let post of postsOfThisId) {
- post.querySelector(".labelId").setAttribute("data-posts-by-this-id", postsOfThisId.length);
- }
- }
- styleIdText(label);
- label.onclick = function() {
- var index = posting.highLightedIds.indexOf(id);
- window.location.hash = '_';
- if (index > -1) {
- posting.highLightedIds.splice(index, 1);
- } else {
- posting.highLightedIds.push(id);
- }
- for (var i = 0; i < postsOfThisId.length; i++) {
- var cellToChange = array[i];
- if (cellToChange.className === 'innerOP') {
- continue;
- }
- /*? 'innerPost' : 'markedPost';*/
- cellToChange.classList.toggle("markedPost", index === -1);
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment