巴哈姆特進階文章篩選

哈拉版的進階文章篩選功能

目前為 2018-04-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         巴哈姆特進階文章篩選
// @namespace    https://blog.maple3142.net/
// @version      0.1
// @description  哈拉版的進階文章篩選功能
// @author       maple3142
// @require      https://unpkg.com/[email protected]/dist/vue.min.js
// @require      https://unpkg.com/[email protected]/dist/vuejs-storage.min.js
// @match        https://forum.gamer.com.tw/B.php?*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function($,egg) {
    'use strict'
    // UI
    $('.b-list__filter').append(`<div id="x_filter">
<button-checkbox v-model="filter.hidelock">隱藏鎖文</button-checkbox>
<button-checkbox v-model="filter.hidetop">隱藏置頂</button-checkbox>
<button-checkbox v-model="filter.hideimg">隱藏有圖片的文章</button-checkbox>
</div>`)
    Vue.use(vuejsStorage)
    Vue.component('ButtonCheckbox',{
        template: `
<button class="ButtonCheckbox" :class="{active: checked}" @click.prevent="$emit('input',checked=!checked)"><slot/></button>`,
        props: ['value'],
        data(){
            return {
                checked: this.value
            }
        }
    })
    const vm=new Vue({
        el: '#x_filter',
        data: {
            filter: {
                hidelock: false,
                hidetop: false,
                hideimg: false
            }
        },
        storage: {
            namespace: 'x_filter',
            keys: ['filter'],
            storage:{
                setItem: GM_setValue,
                getItem: GM_getValue
            }
        }
    })

    // LOGIC
    const isLocked=el=>$(el).find('.icon-lock').length>0
    const isTop=el=>$(el).hasClass('b-list__row--sticky')
    const isImg=el=>$(el).find('.icon-photo').length>0
    function render(){
        $('.b-list>tbody>.b-list__row').each((i,el)=>{
            if(vm.filter.hidelock && isLocked(el)){
                $(el).hide()
            }
            else if(vm.filter.hidetop && isTop(el)){
                $(el).hide()
            }
            else if(vm.filter.hideimg && isImg(el)){
                $(el).hide()
            }
            else{
                $(el).show()
            }
        })
    }
    vm.$watch('filter',{handler:render,deep:true})
    render()
    const css=document.createElement('style')
    css.textContent=`
#x_filter{
display: inline-block;
}
.ButtonCheckbox{
display: inline-block;
border: 0;
border-radius: 3px;
padding: 3px 12px;
height: 25px;
background-color: #117e96;
color: #FFF;
font-size: 12px;
margin-left: 5px;
}
.ButtonCheckbox.active{
background-color: #222e96;
}
`
    document.body.appendChild(css)
})(jQuery,$)