Greasy Fork

Greasy Fork is available in English.

ACM 论文重新打开

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);
                    }
                }
            }
        });
        */
    }
})();