Refactor simplify liveroom

This commit is contained in:
the1812 2019-09-27 12:48:47 +08:00
parent da88552418
commit f6ed0674b4
9 changed files with 77 additions and 58 deletions

View File

@ -144,12 +144,15 @@ declare global {
static select<T>(query: () => T, action: (queryResult: T) => void, failed?: () => void): void;
static select<T>(query: () => T): Promise<T>;
static select(query: string): Promise<HTMLElement | null>;
static select(query: string, action: (queryResult: HTMLElement) => void, failed?: () => void): void;
static any<T>(query: () => T, action: (queryResult: T) => void, failed?: () => void): void;
static any<T>(query: () => T): Promise<T>;
static any(query: string): Promise<any>;
static any(query: string): Promise<JQuery>;
static any(query: string, action: (queryResult: JQuery) => void, failed?: () => void): void;
static count<T>(query: () => T, count: number, success: (queryResult: T) => void, failed?: () => void): void;
static count<T>(query: () => T, count: number): Promise<T>;
static count(query: string, count: number): Promise<NodeListOf<Element>>;
static count(query: string, count: number, success: (queryResult: NodeListOf<Element>) => void, failed?: () => void): Promise<void>;
static unsafeJquery(action: () => void, failed?: () => void): void;
static unsafeJquery(): Promise<void>;
}
@ -308,6 +311,7 @@ declare global {
guardPurchase: boolean,
popup: boolean,
skin: boolean,
[key: string]: boolean,
},
customNavbar: boolean,
customNavbarFill: boolean,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -131,7 +131,7 @@
"simplify-home.min.js": "F6D7F8E0D45847C3E056711AECE3832785603E7EF85A4B995C028F5CBE539C94",
"simplify-home.vue.min.js": "073A24094C480D6DD79006C3704002563AD9DF1BA496FF937DFE4A25869722E8",
"simplify-liveroom.min.css": "97060C7E91C8BC39534EC6A415C20AC2E5A29697A88E93F995EA112E145245D7",
"simplify-liveroom.min.js": "2B6451D73AEC992DD251341F78547A196057C4DD1AD37A4BB6F01A2E8A2EC370",
"simplify-liveroom.min.js": "16C7DFF5204E5A020371C5F050A9557C65C8B25283145FBC6BBD892E82016C35",
"skip-charge-list.min.css": "D3C988CE131CEBFAC8A60360529C83EC4AE1B9EA122F9A6924F19963E25A4FE9",
"skip-charge-list.min.js": "D057258F8EE77D949147174585B1A8C640DDB74E0C0B711A50AEAC8D6792F49F",
"slip.min.js": "0905C7F3B0BFA6535D48CA9A4D2DDCE0EDD83E66AA3D19AA3C1A6A53ECDD15FE",

Binary file not shown.

View File

@ -1 +1 @@
(()=>{return(e,i)=>{const s={vip:"老爷图标",fansMedal:"粉丝勋章",title:"活动头衔",userLevel:"用户等级",guard:"舰长图标",systemMessage:"全区广播",welcomeMessage:"欢迎信息",giftMessage:"礼物弹幕",guardPurchase:"上舰提示",giftPanel:"付费礼物",eventsBanner:"活动横幅",popup:"抽奖提示",skin:"房间皮肤"};let t=e.simplifyLiveroomSettings.skin;const n=["#head-info-vm","#gift-control-vm","#rank-list-vm","#rank-list-ctnr-box",".gift-panel.base-panel",".gift-panel.extend-panel",".seeds-wrap>div:first-child",".gift-section>div:last-child",".z-gift-package>div>div",".right-action"];const c="live-skin-coloration-area";n.forEach(e=>{SpinQuery.select(e,i=>{Observer.attributes(e,e=>{e.forEach(e=>{if(e.attributeName==="class"){if(t&&i.classList.contains(c)){i.classList.remove(c)}else if(!t&&!i.classList.contains(c)){i.classList.add(c)}}})})})});const a=(e,i)=>{document.body.classList[e?"add":"remove"](`simplify-${i}`);if(i==="skin"){t=e;n.forEach(i=>{SpinQuery.select(i,i=>i.classList[e?"remove":"add"]("live-skin-coloration-area"))})}};const o=()=>document.URL.startsWith(`https://live.bilibili.com/`);if(o()){Object.keys(s).forEach(i=>{const s=e.simplifyLiveroomSettings[i];a(s,i)})}return{widget:{condition:o,content:`\n<div class="gui-settings-flat-button" style="position: relative" id="simplify-liveroom">\n<i class="mdi mdi-24px mdi-settings"></i>\n<span>简化直播间</span>\n<div class="simplify-liveroom-settings popup">\n<ul>\n<li v-for="item in items" v-on:click="itemClick(item)">\n<i class="mdi mdi-18px" v-bind:class="{'mdi-eye': !item.checked, 'mdi-eye-off': item.checked}"></i>\n{{item.name}}\n</li>\n</ul>\n</div>\n</div>\n`,success:()=>{const i=document.querySelector("#simplify-liveroom");const t=document.querySelector(".gui-settings-mask");i.addEventListener("click",e=>{const i=document.querySelector(".simplify-liveroom-settings");if(i.contains(e.target)||e.target===i){return}i.classList.toggle("opened")});i.addEventListener("mouseenter",()=>t.classList.add("transparent"));i.addEventListener("mouseleave",()=>t.classList.remove("transparent"));new Vue({el:".simplify-liveroom-settings",data:{items:Object.entries(s).map(([i,s])=>{const t=e.simplifyLiveroomSettings[i];a(t,i);return{key:i,name:s,checked:t}})},methods:{itemClick(i){i.checked=!i.checked;a(i.checked,i.key);e.simplifyLiveroomSettings=Object.assign(e.simplifyLiveroomSettings,{[i.key]:i.checked})}}})}}}}})();
(()=>{return(e,i)=>{const s={vip:"老爷图标",fansMedal:"粉丝勋章",title:"活动头衔",userLevel:"用户等级",guard:"舰长图标",systemMessage:"全区广播",welcomeMessage:"欢迎信息",giftMessage:"礼物弹幕",guardPurchase:"上舰提示",giftPanel:"付费礼物",eventsBanner:"活动横幅",popup:"抽奖提示",skin:"房间皮肤"};class t{constructor(i,s){this.skinDisabled=e.simplifyLiveroomSettings.skin;this.skinSelectors=i;this.skinClass=s;i.forEach(e=>{SpinQuery.select(e,i=>{Observer.attributes(e,e=>{e.forEach(e=>{if(e.attributeName==="class"){if(this.skinDisabled&&i.classList.contains(s)){i.classList.remove(s)}else if(!this.skinDisabled&&!i.classList.contains(s)){i.classList.add(s)}}})})})})}setSkin(e){this.skinDisabled=!e;this.skinSelectors.forEach(i=>{SpinQuery.select(i,i=>i.classList[e?"add":"remove"](this.skinClass))})}}const n=[new t(["#head-info-vm","#gift-control-vm","#rank-list-vm","#rank-list-ctnr-box",".gift-panel.base-panel",".gift-panel.extend-panel",".seeds-wrap>div:first-child",".gift-section>div:last-child",".z-gift-package>div>div",".right-action"],"live-skin-coloration-area"),new t([".rank-list-ctnr .tabs"],"isHundred"),new t([".rank-list-ctnr .tab-content > div"],"hundred")];const a=(e,i)=>{document.body.classList[e?"add":"remove"](`simplify-${i}`);if(i==="skin"){n.forEach(i=>i.setSkin(!e))}};const c=()=>document.URL.startsWith(`https://live.bilibili.com/`);if(c()){Object.keys(s).forEach(i=>{const s=e.simplifyLiveroomSettings[i];a(s,i)})}return{widget:{condition:c,content:`\n<div class="gui-settings-flat-button" style="position: relative" id="simplify-liveroom">\n<i class="mdi mdi-24px mdi-settings"></i>\n<span>简化直播间</span>\n<div class="simplify-liveroom-settings popup">\n<ul>\n<li v-for="item in items" v-on:click="itemClick(item)">\n<i class="mdi mdi-18px" v-bind:class="{'mdi-eye': !item.checked, 'mdi-eye-off': item.checked}"></i>\n{{item.name}}\n</li>\n</ul>\n</div>\n</div>\n`,success:()=>{const i=document.querySelector("#simplify-liveroom");const t=document.querySelector(".gui-settings-mask");i.addEventListener("click",e=>{const i=document.querySelector(".simplify-liveroom-settings");if(i.contains(e.target)||e.target===i){return}i.classList.toggle("opened")});i.addEventListener("mouseenter",()=>t.classList.add("transparent"));i.addEventListener("mouseleave",()=>t.classList.remove("transparent"));new Vue({el:".simplify-liveroom-settings",data:{items:Object.entries(s).map(([i,s])=>{const t=e.simplifyLiveroomSettings[i];a(t,i);return{key:i,name:s,checked:t}})},methods:{itemClick(i){i.checked=!i.checked;a(i.checked,i.key);e.simplifyLiveroomSettings=Object.assign(e.simplifyLiveroomSettings,{[i.key]:i.checked})}}})}}}}})();

View File

@ -13,49 +13,66 @@ const displayNames = {
popup: "抽奖提示",
skin: "房间皮肤",
}
let skinDisabled = settings.simplifyLiveroomSettings.skin;
const skinSelectors = [
"#head-info-vm",
"#gift-control-vm",
"#rank-list-vm",
"#rank-list-ctnr-box",
".gift-panel.base-panel",
".gift-panel.extend-panel",
".seeds-wrap>div:first-child",
".gift-section>div:last-child",
".z-gift-package>div>div",
".right-action"
];
const skinClass = "live-skin-coloration-area";
skinSelectors.forEach(selector => {
SpinQuery.select(
selector,
skin => {
Observer.attributes(selector, records => {
records.forEach(record => {
if (record.attributeName === "class") {
// console.log("Observed class change: ", record);
if (skinDisabled && skin.classList.contains(skinClass)) {
skin.classList.remove(skinClass);
}
else if (!skinDisabled && !skin.classList.contains(skinClass)) {
skin.classList.add(skinClass);
}
}
});
});
});
});
const setBodyClass = (checked, key) => {
document.body.classList[checked ? "add" : "remove"](`simplify-${key}`);
if (key === "skin") {
skinDisabled = checked;
class SkinManager {
skinDisabled = settings.simplifyLiveroomSettings.skin
skinSelectors: string[]
skinClass: string
constructor(skinSelectors: string[], skinClass: string) {
this.skinSelectors = skinSelectors
this.skinClass = skinClass
skinSelectors.forEach(selector => {
SpinQuery.select(
selector,
skin => skin.classList[checked ? "remove" : "add"]("live-skin-coloration-area")
);
});
skin => {
Observer.attributes(selector, records => {
records.forEach(record => {
if (record.attributeName === 'class') {
if (this.skinDisabled && skin.classList.contains(skinClass)) {
skin.classList.remove(skinClass)
}
else if (!this.skinDisabled && !skin.classList.contains(skinClass)) {
skin.classList.add(skinClass)
}
}
})
})
})
})
}
setSkin(enable: boolean) {
this.skinDisabled = !enable
this.skinSelectors.forEach(selector => {
SpinQuery.select(
selector,
skin => skin.classList[enable ? 'add' : 'remove'](this.skinClass)
)
})
}
}
const skins = [
new SkinManager([
'#head-info-vm',
'#gift-control-vm',
'#rank-list-vm',
'#rank-list-ctnr-box',
'.gift-panel.base-panel',
'.gift-panel.extend-panel',
'.seeds-wrap>div:first-child',
'.gift-section>div:last-child',
'.z-gift-package>div>div',
'.right-action'
], 'live-skin-coloration-area'),
new SkinManager([
'.rank-list-ctnr .tabs'
], 'isHundred'),
new SkinManager([
'.rank-list-ctnr .tab-content > div'
], 'hundred'),
]
const setBodyClass = (checked: boolean, key: string) => {
document.body.classList[checked ? "add" : "remove"](`simplify-${key}`);
if (key === "skin") {
skins.forEach(it => it.setSkin(!checked))
}
};
const isLiveroom = () => document.URL.startsWith(`https://live.bilibili.com/`)
@ -83,11 +100,11 @@ export default {
</div>
`,
success: () => {
const button = document.querySelector("#simplify-liveroom");
const mask = document.querySelector(".gui-settings-mask");
const button = document.querySelector("#simplify-liveroom") as HTMLButtonElement
const mask = document.querySelector(".gui-settings-mask") as HTMLElement
button.addEventListener("click", e => {
const settingsList = document.querySelector(".simplify-liveroom-settings");
if (settingsList.contains(e.target) || e.target === settingsList) {
const settingsList = document.querySelector(".simplify-liveroom-settings") as HTMLElement
if (settingsList.contains(e.target as Node) || e.target === settingsList) {
return;
}
settingsList.classList.toggle("opened");
@ -106,15 +123,13 @@ export default {
}),
},
methods: {
itemClick (item) {
itemClick(item: { key: string, name: string, checked: boolean }) {
item.checked = !item.checked;
setBodyClass(item.checked, item.key);
settings.simplifyLiveroomSettings = Object.assign(
settings.simplifyLiveroomSettings, {
[item.key]: item.checked,
});
// settings.simplifyLiveroomSettings[item.key] = item.checked;
// GM_setValue("simplifyLiveroomSettings", settings.simplifyLiveroomSettings);
[item.key]: item.checked,
});
},
},
});