Advertisement
Guest User

Untitled

a guest
Sep 5th, 2023
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.12 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Bilibili SpamRemover
  3. // @namespace    https://example.com/
  4. // @version      0.1
  5. // @description  nil
  6. // @author       -
  7. // @match      *://*.bilibili.com/*
  8. // @run-at document-end
  9. // @grant unsafeWindow
  10. // ==/UserScript==
  11.  
  12.  
  13. function autoClickDialogs() {
  14.   // Fix Dialog Problem.
  15.  
  16.   document.querySelector('body > div.v-dialog > div.v-dialog__wrap > div > div.v-dialog__body > div > div > span')?.click();
  17.   document.querySelector('#app > div > div > div.natural-module > div.fixed-module > div.natural-main-video > div.main-info > div.btn')?.click();
  18.   document.querySelector('body > div.v-dialog.natural-dialog > div.v-dialog__wrap > div > div.v-dialog__body > div > div.to-see')?.click();
  19. }
  20.  
  21. function repairMobileCardBox() {
  22.   // Fix CardItem Url;
  23.  
  24.   let cardBoxElement = document.getElementsByClassName('card-box')[0]?.children;
  25.   if (cardBoxElement === undefined) { return };
  26.  
  27.   for (let cardItem of cardBoxElement) {
  28.       if (cardItem.passed) { continue; }
  29.  
  30.       let bvid = cardItem?.__vue__?.$options?.propsData?.info?.bvid;
  31.       if (!bvid) { continue; }
  32.  
  33.       let oldElement = cardItem;
  34.       let newElement = oldElement.cloneNode(true);
  35.       newElement.passed = true;
  36.  
  37.       newElement.onclick = () => {
  38.           window.location = 'https://m.bilibili.com/video/' + bvid;
  39.       };
  40.  
  41.       oldElement.parentNode.replaceChild(newElement, oldElement);
  42.   }
  43. }
  44.  
  45. function removeCardBoxOpenAppTags () {
  46.   // Remove CardBoxOpenApp Tags.
  47.  
  48.   let cardBoxOpenAppTags = document.getElementsByClassName('open-app weakened');
  49.   if (cardBoxOpenAppTags === undefined) { return; };
  50.  
  51.   for (let openAppTag of cardBoxOpenAppTags) {
  52.       if (openAppTag.passed) { continue; }
  53.  
  54.       openAppTag.style.display = 'none';
  55.       openAppTag.passed = true;
  56.   }
  57. }
  58.  
  59. function repairMobileTitleClick() {
  60.   // Repair Title.
  61.  
  62.   let titleElement = document.getElementsByClassName('title-wrapper')[0];
  63.  
  64.   if (titleElement && !titleElement.passed) {
  65.     let oldTitleElement = titleElement;
  66.     let newTitleElement = oldTitleElement.cloneNode(true);
  67.  
  68.     newTitleElement.passed = true
  69.     oldTitleElement.parentNode.replaceChild(newTitleElement, oldTitleElement);
  70.   }
  71. }
  72.  
  73. function repairComment() {
  74.   // Enable Comments.
  75.  
  76.   let commentElement = document.querySelector('#comment');
  77.   if (!commentElement) { return; }
  78.   if (!commentElement.__vue__) { return; }
  79.   if (!commentElement.__vue__.user) { return; }
  80.  
  81.   if (commentElement && !commentElement.__vue__.user.isLogin) {
  82.     commentElement.__vue__.user.isLogin = true
  83.     commentElement.__vue__.initComment();
  84.   }
  85. }
  86.  
  87. function processHandler() {
  88.   autoClickDialogs();
  89.   repairMobileCardBox();
  90.   removeCardBoxOpenAppTags();
  91.   repairMobileTitleClick();
  92.   repairComment();
  93. }
  94.  
  95. (function() {
  96.   "use strict";
  97.   setInterval(processHandler, 300);
  98. })();
  99.  
  100. // Disable Click Spam Copy ExecCommand Event.
  101.  
  102. unsafeWindow.document.execCommand = () => {};
  103.  
  104. // Disable Click FullScreen Button Auto Download Application.
  105.  
  106. let playerAgent = unsafeWindow.window?.PlayerAgent;
  107.  
  108. if (playerAgent) {
  109.     playerAgent.openApp = () => {};
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement