PDF Link Extractor

Provides a link at the top of the page to the original PDF, e.g. a datasheet (useful on annoying websites that make you view PDFs through a frame surrounded by ads).

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         PDF Link Extractor
// @namespace    https://nbolton.com
// @version      0.2
// @description  Provides a link at the top of the page to the original PDF, e.g. a datasheet (useful on annoying websites that make you view PDFs through a frame surrounded by ads).
// @author       Nick Bolton
// @match        *://*/*
// @exclude      *google.*
// @exclude      *greasyfork.*
// @icon         https://cdn3.iconfinder.com/data/icons/document-icons-2/30/647710-pdf-512.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let match = document.body.innerHTML.match(/["']([^"']*?\.pdf[^"']*?)['"]/i);
    console.log('match', match);

    if (match) {

        const a = document.createElement('a');
        a.textContent = 'Go to PDF';
        a.style.fontSize = '15px';
        a.href = match[1];

        const img = document.createElement('img');
        img.width = 16;
        img.height = 16;
        img.style.marginRight = '10px';
        img.style.marginBottom = '-3px';
        img.src = 'https://cdn3.iconfinder.com/data/icons/document-icons-2/30/647710-pdf-512.png';

        const p = document.createElement('p');
        p.style.margin = '0px';
        p.style.padding = '0px';
        p.style.height = '20px';
        p.appendChild(img);
        p.appendChild(a);

        const div = document.createElement('div');
        div.style.backgroundColor = 'white';
        div.style.color = 'black';
        div.style.padding = '10px';
        div.style.borderBottom = '2px dashed grey';
        div.appendChild(p);

        document.body.insertBefore(div, document.body.firstChild);
    }
    else {
        console.log("No PDF found");
    }
})();