Greasy Fork is available in English.

FanfictionQomplete

Appends all following chapters and strips off junk.

Pada tanggal 01 Juni 2015. Lihat %(latest_version_link).

// ==UserScript==
// @name          FanfictionQomplete
// @description   Appends all following chapters and strips off junk.
// @namespace     https://www.fanfiction.net
// @include       https://www.fanfiction.net/s/*/*
// @version 0.0.1.20150601215022
// ==/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 chapdiv = page.createElement('div')
        var storytext = page.getElementById('storytext')
        if (storytext) {
            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)
            return chapdiv
        } else return null
    }
    var 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) {
        try {
            ptbuttons[0].remove()
            for (; head.firstElementChild;) head.firstElementChild.remove();
            for (; body.firstElementChild;) body.firstElementChild.remove();
        } catch (e) {
            console.log('Error: failed to remove stuff!')
            // try {
            //     ptbuttons[0].removeNode(true)
            //     var elementChildren = head.children;
            //     for (; elementChildren.length;) {
            //         elementChildren[0].removeNode(true)
            //     }
            //     var elementChildren = body.children;
            //     for (; elementChildren.length;) {
            //         elementChildren[0].removeNode(true)
            //     }
            // } catch (e) {}
        }
    }
    body.removeAttribute('style')

    var style = document.createElement('style')
    style.setAttribute('type', 'text/css')
    style.innerHTML = 'body{background-color:#3f5;color:#ccc;margin:0;padding:0;font-family:"Verdana";}div.wrap{max-width:1200px;margin-left:auto;margin-right:auto;}.chapter,#profile_top{background-color:#222;margin-top:1em;margin-bottom:1em;}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)

    wrap = document.createElement('div')
    wrap.setAttribute('class', 'wrap')

    var div = document.createElement('div')
    div.appendChild(profile_top)
    wrap.appendChild(div)

    wrap.appendChild(chap)
    body.appendChild(wrap)

    // GLOBAL_URL_FOR_IE = ""

    function loadQomplete() {
        var style = document.createElement('style')
        style.setAttribute('type', 'text/css')
        style.innerHTML = 'body{background-color:#604;}'
        head.appendChild(style)
        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) {
                wrap.appendChild(chap)
                appendChapterFromURL(inc(url))
            } else loadQomplete()
        }
        // GLOBAL_URL_FOR_IE = url
        oReq.responseURLfallback = url
        oReq.open("get", url, true);
        oReq.send();
    }

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