Remove inaccessible fav

Remove fav directly

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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.');

})();