Remove inaccessible fav

Remove fav directly

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Remove inaccessible fav
// @namespace    http://tampermonkey.net/
// @version      0.4
// @license      GPL
// @description  Remove fav directly
// @author       You
// @match        https://www.nodeseek.com/space/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nodeseek.com
// @run-at       context-menu
// ==/UserScript==

(function() {
    'use strict';

    function prompt_removal(link, e) {
        if(!confirm('Do you want to remove this link?')) {
            // Continue visiting the link (but for what?)
            return;
        }

        //// remove the link {{

        // Sample: "https://www.nodeseek.com/post-16300-1";
        const match = link.href.match(/post-(\d+)-1/);
        const post_id = parseInt( match[1] );
        console.log(post_id); // eg. 16300

        fetch("https://www.nodeseek.com/api/statistics/collection", {
            method: "POST",
            headers:{"Content-Type": "application/json"},
            body: JSON.stringify({
                postId: post_id,
                action: "remove"
            })
        }).then(response => response.json())
            .then(data => console.log(data))
            .catch(error => console.error(error))

        // }}

        e.preventDefault();
    }

      var links = document.querySelectorAll('.discussion-item');
      links.forEach( link => {
          link.addEventListener('click', (e) => prompt_removal(link, e));
      });

      alert('Clicking on links now offers options to remove them.');

})();