Guest User

Untitled

a guest
May 21st, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Always show post counts by ID - 8chan.moe
  3. // @namespace   Violentmonkey Scripts
  4. // @match       https://*.8chan.moe/*
  5. // @grant       GM_addStyle
  6. // @run-at      document-end
  7. // ==/UserScript==
  8.  
  9. if (typeof posting === "undefined") return;
  10.  
  11. if (typeof GM_addStyle === 'undefined') {
  12.     function GM_addStyle(css) {
  13.         'use strict';
  14.         const style = document.createElement('style');
  15.         style.textContent = css;
  16.         document.head.appendChild(style);
  17.         return style;
  18.     }
  19. }
  20.  
  21. GM_addStyle(`
  22.   .labelId.dark-post-count {
  23.     color: #000c;
  24.   }
  25.  
  26.   .labelId.dark-post-count::after {
  27.     color: #000c;
  28.     border-left: 1px solid #000a;
  29.   }
  30.  
  31.   .labelId.light-post-count {
  32.     color: #fffd;
  33.   }
  34.  
  35.   .labelId.light-post-count::after {
  36.     color: #fffd;
  37.     border-left: 1px solid #fffa;
  38.   }
  39.  
  40.   .labelId::after {
  41.     content: attr(data-posts-by-this-id);
  42.     margin-left: 0.4em;
  43.     padding: 1px 4px;
  44.   }
  45.  
  46.   .labelId {
  47.     background-image: none;
  48.     paint-order: stroke fill;
  49.     padding: 1px 0px 1px 4px; !important;
  50.     text-shadow: none;
  51.   }
  52. `);
  53.  
  54. function linearize(c) {
  55.     return c <= 0.040449936 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
  56. }
  57.  
  58. function toneFromRgb(red, green, blue) {
  59.     const redL = linearize(red), greenL = linearize(green), blueL = linearize(blue);
  60.     const y = (0.2126 * redL + 0.7152 * greenL + 0.0722 * blueL);
  61.     return y > 0.00885645 ? 116.0 * Math.pow(y, 1.0 / 3.0) - 16.0 : 903.296296 * y;
  62. }
  63.  
  64. function styleIdText(label) {
  65.   const hex = label.innerText;
  66.   const r = parseInt(hex.substring(0, 2), 16) / 255;
  67.   const g = parseInt(hex.substring(2, 4), 16) / 255;
  68.   const b = parseInt(hex.substring(4, 6), 16) / 255;
  69.   label.classList.add(toneFromRgb(r, g, b) >= 57 ? "dark-post-count" : "light-post-count");
  70. }
  71.  
  72. // Process all the posts that was rendered before this script runs.
  73. for (const [id, posts] of Object.entries(posting.idsRelation)) {
  74.   for (const post of posts) {
  75.     const label = post.querySelector(".labelId");
  76.     // Remove these listeners because our hook doesn't work during page load (wtf Lynxchan?)
  77.     label.onmouseover = null;
  78.     label.onmouseout = null;
  79.     // Set the post count.
  80.     label.setAttribute("data-posts-by-this-id", posts.length);
  81.     styleIdText(label);
  82.   }
  83. }
  84.  
  85. // This was pasted straight from 8chan.moe source code.
  86. posting.processIdLabel = function(label) {
  87.   if (!label) return;
  88.  
  89.   const id = label.textContent;
  90.   const postsOfThisId = posting.idsRelation[id] || [];
  91.   const innerPost = label.closest(".innerPost, .innerOP");
  92.  
  93.   if (innerPost.classList.contains("clone")) {
  94.     label.setAttribute("data-posts-by-this-id", postsOfThisId.length);
  95.   } else {
  96.     posting.idsRelation[id] = postsOfThisId;
  97.     postsOfThisId.push(innerPost);
  98.  
  99.     // Update the count for all the .labelID elements of this ID.
  100.     for (let post of postsOfThisId) {
  101.       post.querySelector(".labelId").setAttribute("data-posts-by-this-id", postsOfThisId.length);
  102.     }
  103.   }
  104.  
  105.   styleIdText(label);
  106.  
  107.   label.onclick = function() {
  108.     var index = posting.highLightedIds.indexOf(id);
  109.     window.location.hash = '_';
  110.  
  111.     if (index > -1) {
  112.       posting.highLightedIds.splice(index, 1);
  113.     } else {
  114.       posting.highLightedIds.push(id);
  115.     }
  116.  
  117.     for (var i = 0; i < postsOfThisId.length; i++) {
  118.       var cellToChange = array[i];
  119.  
  120.       if (cellToChange.className === 'innerOP') {
  121.         continue;
  122.       }
  123.  
  124.       /*? 'innerPost' : 'markedPost';*/
  125.       cellToChange.classList.toggle("markedPost", index === -1);
  126.     }
  127.   };
  128. };
  129.  
Advertisement
Add Comment
Please, Sign In to add comment