gaoqingFM

gaoqingFM 添加關聯豆瓣按鈕

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         gaoqingFM
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  gaoqingFM 添加關聯豆瓣按鈕
// @author       backrock12
// @match        https://gaoqing.fm/
// @match        https://gaoqing.fm/view/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gaoqing.fm
// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  let isrun = false;
  function sethomepage() {
    if (isrun) return;
    isrun = true;
    console.log("1");
    // const i = $('.pg-items');
    // if (i.attr('gaoqingFM')) return;
    // i.attr('gaoqingFM', true)
    const list = $("#result1 > li > div:nth-child(1) > div:nth-child(2) > p ");
    console.log(list);
    $.each(list, function (index, element) {
      if ($(element).attr("gaoqingFM")) return;
      $(element).attr("gaoqingFM", true);
      const name = $(element).find("a").text();
      console.log(name);
      const aurl =
        "<a href='https://www.douban.com/search?cat=1002&q=" +
        name +
        "#autoselect' target='_blank' > <img src='https://www.douban.com/favicon.ico' style='width:24px;' alt='豆瓣' /> </a>";
      $(element).append(aurl);
    });
    isrun = false;
  }

  function subnoad() {
    const adlist = [
      "#notice",
      "ul.navbar-nav:nth-child(2)",
      "#cililian > a:nth-child(3)",
      "#sidebar",
    ];

    GM_addStyle(adlist.join(",") + " { display:none  !important; }");
  }

  function setitempage() {
    const ent = $(".col-md-12 > h2");
    console.log(ent);
    const name = $(ent).find("a").text();
    console.log(name);
    const aurl =
      "<a href='https://www.douban.com/search?cat=1002&q=" +
      name +
      "#autoselect' target='_blank' > <img src='https://www.douban.com/favicon.ico' style='width:32px;' alt='豆瓣' /> </a>";
    $(ent).append(aurl);
  }

  function run() {
    subnoad();
    if (/view/.test(location.href)) {
      setitempage();
    } else {
      sethomepage();

      const config = {
        //attributes: true,
        childList: true,
        //subtree: true
      };
      const observer = new MutationObserver(sethomepage);
      observer.observe($("#result1")[0], config);
    }
  }

  run();
})();