Gmail Unsubscribe Github issues

Unsubscribe by pressing \

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Gmail Unsubscribe Github issues
// @namespace    https://violentmonkey.github.io/
// @version      0.1.6
// @license      MIT
// @grant        GM.openInTab
// @grant        window.close
// @description  Unsubscribe by pressing \
// @match        https://mail.google.com/*
// @icon         https://www.google.com/s2/favicons?domain=tampermonkey.net
// ==/UserScript==

function unsubscribe(event) {
  if (event.key !== "\\") {
    return;
  }

  const link = Array.from(document.querySelectorAll('a[href^="https://github.com/notifications/unsubscribe-auth/"]')).findLast(node => node.innerText === 'unsubscribe');
  if (!link) {
    console.log("no link");
    return;
  }
  console.log(link);
  let tabControl = GM.openInTab(link.href, true);
  console.log("link open");

  setTimeout(() => {
    tabControl.close();
    console.log("tab close");
  },5000);

  const downEvt = new MouseEvent("mousedown");
  const upEvt = new MouseEvent("mouseup");

  const del = Array.from(document.querySelectorAll('[role="button"]')).find(node => node.innerText === 'Delete')
  console.log(del);

  if (!del) {
    console.log("no delete");
      return;
  }

  del.dispatchEvent(downEvt);
  setTimeout(() => del.dispatchEvent(upEvt));
  console.log("del evt");
}

(function() {
    'use strict';
    document.addEventListener('keypress', unsubscribe);
})();