ACM 论文重新打开

当你第二天再次打开ACM里的论文时,这个脚本能帮你重新打开已经失效的pdf页面

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         ACM 论文重新打开
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  当你第二天再次打开ACM里的论文时,这个脚本能帮你重新打开已经失效的pdf页面
// @author       tty112358
// @match        *://delivery.acm.org/*
// @match        *://dl.acm.org/*
// @grant        GM_xmlhttpRequest
// @grant        GM_openInTab
// @connect      dl.acm.org
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    const curURL = new URL(window.location.href);
    console.log(curURL);

    if (curURL.searchParams.has('id')){
        const id = curURL.searchParams.get('id');
        if (curURL.host === "dl.acm.org" && curURL.searchParams.has('from_tty112358') && curURL.searchParams.get('from_tty112358') === '1'){
            for (const node of document.querySelectorAll("a[name=FullTextPDF]")){
                const href = node.href;
                const toURL = new URL(href);
                if (toURL.searchParams.has('id') && toURL.searchParams.get('id') === id){
                    // console.log(node);
                    // console.log(href);
                    node.click();
                    break;
                }
            }
            window.close();
        } else if (curURL.host === "delivery.acm.org") {
            const pdfEmbed = document.querySelector('embed');
             if(pdfEmbed){
                // do nothing and peace out
                return;
            }
            const paperHref = 'https://dl.acm.org/citation.cfm?id=' + id + '&from_tty112358=1';
            console.log(paperHref);
            GM_openInTab(paperHref);
        } else {
            // no job here
        }
        /*
        GM_xmlhttpRequest ({
            method: 'GET',
            url: paperHref,
            onload: function (response) {
                const text = response.responseText;
                const template = document.createElement('template');
                template.innerHTML = text.trim();
                for (const node of template.content.querySelectorAll("a[name=FullTextPDF]")){
                    const href = node.href;
                    const toURL = new URL(href);
                    if (toURL.searchParams.has('id') && toURL.searchParams.get('id') === id){
                        console.log(node);
                        console.log(href);
                        node.click();
                        // GM_openInTab(href);
                    }
                }
            }
        });
        */
    }
})();