Anonfiles PDF Viewer

Adds a button to view PDF files without needing to download them.

当前为 2023-03-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Anonfiles PDF Viewer
// @namespace    https://leaked.wiki
// @version      0.1
// @description  Adds a button to view PDF files without needing to download them.
// @author       Sango
// @match        *://anonfiles.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=anonfiles.com
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    // Change this to true if you want it to always show the PDF
    const ALWAYS_SHOW = false,
          PDF_HEIGHT = '800px';

    const icon = '<img src="/img/file/filetypes/ext/pdf.png">';
    // Check if file is a PDF
    const downloadUrl = document.getElementById('download-url');
    if (downloadUrl && downloadUrl.href.toLowerCase().endsWith('pdf')) {
        // Create a button to show the PDF
        const pdfBtn = document.createElement('a');
        pdfBtn.href = '#Sango';
        pdfBtn.id = 'show-pdf';
        pdfBtn.type = 'button';
        pdfBtn.className = 'btn btn-primary btn-block';
        pdfBtn.style.background = '#245488';
        pdfBtn.innerHTML = icon + ' View as PDF';
        if (!ALWAYS_SHOW) downloadUrl.parentNode.insertBefore(pdfBtn, downloadUrl);

        // Create an iframe element to embed the PDF
        const pdfFrame = Object.assign(document.createElement('iframe'), {
            id: 'pdf-viewer',
            src: 'https://docs.google.com/viewer?url=' + downloadUrl.href + '&embedded=true',
            style: 'width: 100%; height: 100%; min-height: ' + PDF_HEIGHT + "; margin-bottom: 10px; border: 1px solid #245488; background: url(\"data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' style='width:100px;' preserveAspectRatio='xMidYMid' viewBox='10.67 44 78.67 12'%3E%3Cg transform='translate(16.666666666666668 50)'%3E%3Ccircle cx='0' cy='0' r='6' fill='%234087b6'%3E%3CanimateTransform attributeName='transform' type='scale' begin='-0.4938271604938271s' calcMode='spline' keySplines='0.3 0 0.7 1;0.3 0 0.7 1' values='0;1;0' keyTimes='0;0.5;1' dur='1.2345679012345678s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/g%3E%3Cg transform='translate(33.333333333333336 50)'%3E%3Ccircle cx='0' cy='0' r='6' fill='%233886ba'%3E%3CanimateTransform attributeName='transform' type='scale' begin='-0.3703703703703703s' calcMode='spline' keySplines='0.3 0 0.7 1;0.3 0 0.7 1' values='0;1;0' keyTimes='0;0.5;1' dur='1.2345679012345678s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/g%3E%3Cg transform='translate(50 50)'%3E%3Ccircle cx='0' cy='0' r='6' fill='%235298c7'%3E%3CanimateTransform attributeName='transform' type='scale' begin='-0.24691358024691354s' calcMode='spline' keySplines='0.3 0 0.7 1;0.3 0 0.7 1' values='0;1;0' keyTimes='0;0.5;1' dur='1.2345679012345678s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/g%3E%3Cg transform='translate(66.66666666666667 50)'%3E%3Ccircle cx='0' cy='0' r='6' fill='%234591c2'%3E%3CanimateTransform attributeName='transform' type='scale' begin='-0.12345679012345677s' calcMode='spline' keySplines='0.3 0 0.7 1;0.3 0 0.7 1' values='0;1;0' keyTimes='0;0.5;1' dur='1.2345679012345678s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/g%3E%3Cg transform='translate(83.33333333333333 50)'%3E%3Ccircle cx='0' cy='0' r='6' fill='%234087b6'%3E%3CanimateTransform attributeName='transform' type='scale' begin='0s' calcMode='spline' keySplines='0.3 0 0.7 1;0.3 0 0.7 1' values='0;1;0' keyTimes='0;0.5;1' dur='1.2345679012345678s' repeatCount='indefinite'%3E%3C/animateTransform%3E%3C/circle%3E%3C/g%3E%3C/svg%3E\") center / 200px no-repeat;"
        });

        // Add button functionality
        if (ALWAYS_SHOW) document.querySelector('.top-wrapper').appendChild(pdfFrame);
        else {
            document.getElementById('show-pdf').addEventListener('click', (e) => {
                var pdfViewer = document.getElementById('pdf-viewer');
                if (e.target.text == ' View as PDF') {
                    if (pdfViewer) pdfViewer.style.display = ''
                    else document.getElementsByClassName('top-wrapper')[0].appendChild(pdfFrame);
                    e.target.innerHTML = icon + ' Hide PDF';
                } else {
                    e.target.innerHTML = icon + ' View as PDF';
                    pdfViewer.style.display = 'none';
                }
            });
        }
    };
})();