Pjax Everywhere

enable pjax for some sites, speed up access to the site.

目前為 2019-01-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pjax Everywhere
// @namespace    https://github.com/slaier/pjax-everywhere
// @version      0.1
// @author       newbie <[email protected]>
// @description  enable pjax for some sites, speed up access to the site.
// @description:zh 为一些网站开启pjax, 加速访问该网站。
// @include      https://git-scm.com/book/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/jquery.pjax.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/nprogress.min.js
// @resource     nprogressCSS     https://cdn.jsdelivr.net/npm/[email protected]/nprogress.css
// @resource     loadingCSS     https://raw.githubusercontent.com/slaier/pjax-everywhere/master/loading.css?t=1546656015
// @resource     config     https://raw.githubusercontent.com/slaier/pjax-everywhere/master/config.json
// @grant       GM_addStyle
// @grant       GM_getResourceText
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    // 加载nprogress的CSS
    let nprogressCSS = GM_getResourceText ("nprogressCSS");
    GM_addStyle (nprogressCSS);
    // loading 动画
    let loadingCSS = GM_getResourceText ("loadingCSS");
    GM_addStyle (loadingCSS);
    let loading = '<div id="loading-wrap" style="display: none;"  ontouchmove="event.preventDefault()" onscroll="event.preventDefault()"><div id="loading-anime" style="background-image:url(https://raw.githubusercontent.com/slaier/pjax-everywhere/master/loading.png)"></div></div>';
    $('body').append(loading);
    // 读取配置文件
    let config = GM_getResourceText('config');
    config = JSON.parse(config);
    $.pjax.defaults.timeout = config['timeout'];

    let configs = config['config'];
    for(let i = 0; i < configs.length; ++i){
        let arg = configs[i];
        let href = location.href;
        let reg = new RegExp(arg['match'], "gi");
        if (reg.test(href)){
            $(document).pjax(arg['selector'], arg['options']);
            break;
        }
    }
    $(document).on('pjax:start', function() {
        NProgress.start();
        $("#loading-wrap").show();
    });
    $(document).on('pjax:end',   function() {
        NProgress.done();
        $("#loading-wrap").fadeOut(300);
    });
})();