Show More Forum Discussions on Anime/Manga Pages

Show More Forum Discussions on Anime and Manga Pages

当前为 2020-11-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         Show More Forum Discussions on Anime/Manga Pages
// @namespace    ShowMoreDiscussions
// @version      0.4
// @description  Show More Forum Discussions on Anime and Manga Pages
// @author       hacker09
// @include      /^https:\/\/myanimelist\.net\/anime\/[\d]+(\/.*)?/
// @include      /^https:\/\/myanimelist\.net\/manga\/[\d]+(\/.*)?/
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  if (document.querySelector("#forumTopics").rows.length >= 2) //Execute the script only if the page already has 2 or more discussions being shown
   { //Starts the if condition
    async function GetMoreDiscussions() //Creates a function to get the morediscussions
    { //Starts the function
      const response = await fetch($("a:contains('Forum')")[1].href); //Fetch
      const html = await response.text(); //Gets the fetch response
      const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
      var content = newDocument.querySelector("div.page-forum"); //Creates a variable to hold the more discussions

      function findTheMoreDiscussionsaElement() {const headers = [...document.querySelectorAll("a")]; //Select all h2 elements on MAL
        return headers.find(a => a.textContent === "More discussions");} //Find the h2 element that has the text Recent Forum Discussion
      findTheMoreDiscussionsaElement(); //Call the function findTheMoreDiscussionsaElement
      findTheMoreDiscussionsaElement().remove(); //Remove the a element text
      function findTheRecentForumFiscussionheader() {const headers = [...document.querySelectorAll("h2")]; //Select all h2 elements on MAL
        return headers.find(h2 => h2.textContent === "Recent Forum Discussion");} //Find the h2 element that has the text Recent Forum Discussion
      findTheRecentForumFiscussionheader(); //Call the function findTheRecentForumFiscussionheader

      document.querySelector("div.page-forum").appendChild(content); //Append more discussions content on the Recent Forum Discussion
      findTheRecentForumFiscussionheader().innerHTML = ''; //Remove the header text
      document.querySelector("#forumTopics").remove(); //Remove the old discussions
  } //Finishes the async function
  GetMoreDiscussions(); //Starts the function
 } //Finishes the if condition
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址