FanfictionQomplete

Loads all following chapters on fanfiction.net and strips off bloat.

当前为 2015-06-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          FanfictionQomplete
// @description   Loads all following chapters on fanfiction.net and strips off bloat.
// @namespace     https://greasyfork.org/en/users/11891-qon
// @author        Qon
// @include       https://www.fanfiction.net/s/*/*
// @noframes
// @grant         none
// @license       Simple Public License 2.0 (SimPL) https://tldrlegal.com/license/simple-public-license-2.0-%28simpl%29
// @version 0.0.1.20150608034858
// ==/UserScript==

if (Element.prototype.remove == undefined) {
    Element.prototype.remove = function() {
        this.parentNode.removeChild(this)
    }
}

function injectRunButton() {
    var lc = document.getElementsByClassName('lc')
    if (lc.length) {
        lc = lc[0]
        var btn = document.createElement('button')
        btn.setAttribute('onclick', 'document.runFFQomplete();')
        btn.setAttribute('class', 'btn')
        btn.setAttribute('style', 'margin-left:12px;margin-right:2px;')
        btn.setAttribute('title', 'Append all following chapters and remove unecessary bloat.')
        btn.innerHTML = 'Qomplete!'
        lc.appendChild(btn)
    }
}
injectRunButton()

document.runFFQomplete = function() {
    function urlGetChap(url) {
        var re = /(^.*?fanfiction\.net\/s\/\d+\/)(\d+)(?:\/?.*$)/
        var arr = re.exec(url)
        return arr[2]
    }

    function urlSetChap(url, n) {
        var re = /(^.*?fanfiction\.net\/s\/\d+\/)(\d+)(?:\/?.*$)/
        var arr = re.exec(url)
        return arr[1] + n
    }

    function inc(url) {
        var re = /(^.*?fanfiction\.net\/s\/\d+\/)(\d+)(?:\/?.*$)/
        var arr = re.exec(url)
        return arr[1] + (parseInt(arr[2]) + 1)
    }

    function createChapFromFfpage(url, page) {
        var storytext = page.getElementById('storytext')
        if (storytext) {
            var wrap = page.createElement('div')
            wrap.setAttribute('class', 'wrap col' + (urlGetChap(url) % 6))
            var pad = page.createElement('div')
            pad.setAttribute('class', 'pad')
            var chapdiv = page.createElement('div')
            chapdiv.setAttribute('class', 'chapter')
            var chapspan = page.createElement('span')
            chapspan.innerHTML = urlGetChap(url) + '. '
            var title = page.getElementsByTagName('title')[0]
            var chaptitle = page.createElement('a')
            chaptitle.setAttribute('href', url)
            chaptitle.innerHTML = title.innerHTML
            chapdiv.appendChild(chapspan)
            chapdiv.appendChild(chaptitle)
            chapdiv.appendChild(document.createElement('hr'))
            chapdiv.appendChild(storytext)
            pad.appendChild(chapdiv)
            wrap.appendChild(pad)
            return wrap
        } else return null
    }
    body = document.getElementsByTagName('body')[0]
    var head = document.getElementsByTagName('head')[0]
    var title = document.getElementsByTagName('title')[0]

    var profile_top = document.getElementById('profile_top')
    var chap = createChapFromFfpage(document.location.href, document)

    var ptbuttons = profile_top.getElementsByTagName('button')
    if (ptbuttons.length) {
        ptbuttons[0].remove()
        for (; head.firstElementChild;) head.firstElementChild.remove();
        for (; body.firstElementChild;) body.firstElementChild.remove();
    }
    body.removeAttribute('style')

    var style = document.createElement('style')
    style.setAttribute('type', 'text/css')
    style.innerHTML =
        'body{background-color:lime;color:#ccc;margin:0;padding:0;font-family:"Verdana";}\
        div.loading{}\
        div.wrap{max-width:1300px;margin-left:auto;margin-right:auto;padding:0px 5px 0px 5px;}\
        div.wrap:first-child{padding-top:5px;margin-top:50px;}\
        div.wrap:last-child{padding-bottom:5px;margin-bottom:50px;}\
        div.pad{background-color:#222;padding:50px;}\
        .col1{background-color:#808;background:linear-gradient(to bottom, #808, #800);}\
        .col2{background-color:#800;background:linear-gradient(to bottom, #800, #880);}\
        .col3{background-color:#880;background:linear-gradient(to bottom, #880, #080);}\
        .col4{background-color:#080;background:linear-gradient(to bottom, #080, #088);}\
        .col5{background-color:#088;background:linear-gradient(to bottom, #088, #008);}\
        .col0{background-color:#008;background:linear-gradient(to bottom, #008, #808);}\
        .profile1{background-color:#777;background:linear-gradient(to bottom, #fff, #808);}\
        .profile2{background-color:#777;background:linear-gradient(to bottom, #fff, #800);}\
        .profile3{background-color:#777;background:linear-gradient(to bottom, #fff, #880);}\
        .profile4{background-color:#777;background:linear-gradient(to bottom, #fff, #080);}\
        .profile5{background-color:#777;background:linear-gradient(to bottom, #fff, #088);}\
        .profile0{background-color:#777;background:linear-gradient(to bottom, #fff, #008);}\
        .chapter{}#profile_top{}img{float:left;}canvas{float:left;}\
        a:link{color:#a05;}a:visited{color:#555;}a:hover{color:#fff;}a:active{color:#a05;}'
    head.appendChild(style)
    head.appendChild(title)

    var wrap = document.createElement('div')
    wrap.setAttribute('class', 'wrap profile' + (urlGetChap(document.location.href) % 6))
    var pad = document.createElement('div')
    pad.setAttribute('class', 'pad')
    pad.appendChild(profile_top)
    wrap.appendChild(pad)
    body.appendChild(wrap)
    body.appendChild(chap)

    function loadQomplete() {
        var style = document.createElement('style')
        style.setAttribute('type', 'text/css')
        style.innerHTML = 'body{background-color:#000;}'
        head.appendChild(style)
        var a = document.getElementsByClassName('skiptranslate')
        for (q of a) {
            q.remove()
        }
        console.log('QOMPLETE')
    }

    function appendChapterFromURL(url) {
        var oReq = new XMLHttpRequest();
        oReq.onload = function() {
            var xmlDoc = new DOMParser().parseFromString(this.responseText, "text/html")
            var url = this.responseURL ? this.responseURL : this.responseURLfallback
            if (!url) {
                console.log('Error: Response has no responseURL field!')
            }
            var chap = createChapFromFfpage(url, xmlDoc)
            if (chap) {
                body.appendChild(chap)
                appendChapterFromURL(inc(url))
            } else loadQomplete()
        }
        oReq.responseURLfallback = url
        oReq.open("get", url, true)
        oReq.send()
    }

    appendChapterFromURL(inc(document.location.href))
}
// document.runFFQomplete()