巴哈姆特進階文章篩選

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

当前为 2018-04-13 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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,$)