Fix bugs, make comments style reloadable

This commit is contained in:
the1812 2019-04-30 17:14:38 +08:00
parent 3e9b5071ca
commit 9ed32e0b7b
12 changed files with 85 additions and 65 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -171,13 +171,14 @@ function loadSettings()
},
set(newValue)
{
value = newValue;
GM_setValue(key, newValue);
const handlers = settingsChangeHandlers[key];
if (handlers)
{
handlers.forEach(h => h(newValue, value));
}
value = newValue;
GM_setValue(key, newValue);
const input = document.querySelector(`input[key=${key}]`);
if (input !== null)
{
@ -455,6 +456,7 @@ function loadResources()
playerShadow: "playerShadow",
narrowDanmaku: "narrowDanmaku",
compactLayout: "compactLayout",
useCommentStyle: "useCommentStyle",
};
for (const [key, data] of Object.entries(Resource.manifest))
{
@ -1650,9 +1652,9 @@ Resource.manifest = {
useCommentStyle: "简化评论区",
},
},
commentDarkStyle: {
path: "comment-dark.min.css"
},
// commentDarkStyle: {
// path: "comment-dark.min.css"
// },
title: {
path: "title.min.js"
},
@ -2048,15 +2050,14 @@ class ResourceManager
const attributes = this.attributes[targetKey];
if (attributes === undefined)
{
const fetchListener = newValue =>
const fetchListener = async newValue =>
{
if (newValue === true)
{
this.fetchByKey(targetKey).then(() =>
{
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
});
await this.styleManager.fetchStyleByKey(targetKey);
await this.fetchByKey(targetKey);
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
}
};
addSettingsListener(key, fetchListener);

View File

@ -171,13 +171,14 @@ function loadSettings()
},
set(newValue)
{
value = newValue;
GM_setValue(key, newValue);
const handlers = settingsChangeHandlers[key];
if (handlers)
{
handlers.forEach(h => h(newValue, value));
}
value = newValue;
GM_setValue(key, newValue);
const input = document.querySelector(`input[key=${key}]`);
if (input !== null)
{
@ -455,6 +456,7 @@ function loadResources()
playerShadow: "playerShadow",
narrowDanmaku: "narrowDanmaku",
compactLayout: "compactLayout",
useCommentStyle: "useCommentStyle",
};
for (const [key, data] of Object.entries(Resource.manifest))
{
@ -1650,9 +1652,9 @@ Resource.manifest = {
useCommentStyle: "简化评论区",
},
},
commentDarkStyle: {
path: "comment-dark.min.css"
},
// commentDarkStyle: {
// path: "comment-dark.min.css"
// },
title: {
path: "title.min.js"
},
@ -2048,15 +2050,14 @@ class ResourceManager
const attributes = this.attributes[targetKey];
if (attributes === undefined)
{
const fetchListener = newValue =>
const fetchListener = async newValue =>
{
if (newValue === true)
{
this.fetchByKey(targetKey).then(() =>
{
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
});
await this.styleManager.fetchStyleByKey(targetKey);
await this.fetchByKey(targetKey);
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
}
};
addSettingsListener(key, fetchListener);

View File

@ -10,6 +10,7 @@ export function loadResources()
playerShadow: "playerShadow",
narrowDanmaku: "narrowDanmaku",
compactLayout: "compactLayout",
useCommentStyle: "useCommentStyle",
};
for (const [key, data] of Object.entries(Resource.manifest))
{

View File

@ -203,15 +203,14 @@ export class ResourceManager
const attributes = this.attributes[targetKey];
if (attributes === undefined)
{
const fetchListener = newValue =>
const fetchListener = async newValue =>
{
if (newValue === true)
{
this.fetchByKey(targetKey).then(() =>
{
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
});
await this.styleManager.fetchStyleByKey(targetKey);
await this.fetchByKey(targetKey);
removeSettingsListener(key, fetchListener);
checkAttribute(key, this.attributes[targetKey]);
}
};
addSettingsListener(key, fetchListener);

View File

@ -462,9 +462,9 @@ Resource.manifest = {
useCommentStyle: "简化评论区",
},
},
commentDarkStyle: {
path: "comment-dark.min.css"
},
// commentDarkStyle: {
// path: "comment-dark.min.css"
// },
title: {
path: "title.min.js"
},

View File

@ -146,13 +146,14 @@ export function loadSettings()
},
set(newValue)
{
value = newValue;
GM_setValue(key, newValue);
const handlers = settingsChangeHandlers[key];
if (handlers)
{
handlers.forEach(h => h(newValue, value));
}
value = newValue;
GM_setValue(key, newValue);
const input = document.querySelector(`input[key=${key}]`);
if (input !== null)
{

2
min/comment.min.js vendored
View File

@ -1 +1 @@
(()=>{return(r,e)=>{}})();
(()=>{return(e,t)=>{t.applyImportantStyle("useCommentStyleStyle");return{reload:()=>t.applyImportantStyle("useCommentStyleStyle"),unload:()=>t.removeStyle("useCommentStyleStyle")}}})();

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,6 @@
// Style key looks strange as it's a generated key
resources.applyImportantStyle("useCommentStyleStyle");
export default {
reload: () => resources.applyImportantStyle("useCommentStyleStyle"),
unload: () => resources.removeStyle("useCommentStyleStyle"),
}

View File

@ -842,6 +842,7 @@ export default {
<i class="mdi mdi-24px mdi-auto-fix"></i>
<span>顶栏次序</span>
</div>`,
condition: () => false, // TODO: remove this line after complete
success: async () =>
{
const settingsPanel = await SpinQuery.select(".custom-navbar-settings");
@ -860,12 +861,20 @@ export default {
},
unload: () =>
{
document.querySelector(".custom-navbar").style.display = "none";
const navbar = document.querySelector(".custom-navbar");
if (navbar !== null)
{
navbar.style.display = "none";
}
resources.removeStyle("customNavbarStyle");
},
reload: () =>
{
document.querySelector(".custom-navbar").style.display = "flex";
const navbar = document.querySelector(".custom-navbar");
if (navbar !== null)
{
navbar.style.display = "flex";
}
resources.applyImportantStyle("customNavbarStyle");
},
};