Add toastInternalError

This commit is contained in:
the1812 2018-11-28 12:24:33 +08:00
parent 67e23f7f45
commit 58bcf083af
9 changed files with 255 additions and 266 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

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Preview)
// @version 1.5.39
// @version 1.5.40
// @description 增强哔哩哔哩Web端体验(预览版分支): 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等.
// @author Grant Howard, Coulomb-G
// @copyright 2018, Grant Howrad (https://github.com/the1812)
@ -58,6 +58,7 @@
autoLightOff: false,
downloadDanmaku: false,
useCache: true,
toastInternalError: false,
cache: {},
};
const fixedSettings = {
@ -72,6 +73,14 @@
latestVersionLink: "https://github.com/the1812/Bilibili-Evolved/raw/preview/bilibili-evolved.preview.user.js",
currentVersion: GM_info.script.version,
};
function logError(message)
{
if (settings.toastInternalError)
{
Toast.error(message, "错误");
}
console.error(message);
}
function loadSettings()
{
for (const key in settings)
@ -343,6 +352,7 @@
],
displayNames: {
toast: "显示消息",
toastInternalError: "显示内部错误消息",
},
},
removeVideoTopMask: {
@ -1070,7 +1080,7 @@
const style = this.text;
if (style === null)
{
console.error("Attempt to get style which is not downloaded.");
logError("Attempt to get style which is not downloaded.");
}
let attributes = `id='${id}'`;
if (this.priority !== undefined)
@ -1146,69 +1156,61 @@
settings.brightness = this.color.brightness;
settings.filterInvert = this.color.filterInvert;
}
fetchByKey(key)
async fetchByKey(key)
{
const resource = Resource.all[key];
if (!resource)
{
return null;
}
const promise = resource.download();
const text = await resource.download().catch(reason =>
{
console.error(`Download error, XHR status: ${reason}`);
Toast.error(`无法下载组件<span>${Resource.all[key].displayName}</span>`, "错误");
});
resource.dependencies
.filter(it => it.type.name === "script")
.forEach(it => this.fetchByKey(it.key));
return new Promise(resolve =>
{
promise.then(text =>
resource.styles
.filter(it => it.condition !== undefined ? it.condition() : true)
.forEach(it =>
{
resource.styles
.filter(it => it.condition !== undefined ? it.condition() : true)
.forEach(it =>
{
const important = typeof it === "object" ? it.important : false;
const key = typeof it === "object" ? it.key : it;
if (important)
{
this.applyImportantStyle(key);
}
else
{
this.applyStyle(key);
}
});
this.applyComponent(key, text);
resolve();
}).catch(reason =>
{
// download error
console.error(`Download error, XHR status: ${reason}`);
Toast.error(`无法下载组件<span>${Resource.all[key].displayName}</span>`, "错误");
});
});
}
fetch()
{
return new Promise(resolve =>
{
this.validateCache();
const promises = [];
for (const key in settings)
{
if (settings[key] === true && key !== "toast")
const important = typeof it === "object" ? it.important : false;
const key = typeof it === "object" ? it.key : it;
if (important)
{
const promise = this.fetchByKey(key);
if (promise)
{
promises.push(promise);
}
this.applyImportantStyle(key);
}
else
{
this.applyStyle(key);
}
});
this.applyComponent(key, text);
}
async fetch()
{
this.validateCache();
if (settings.toast === true)
{
await this.fetchByKey("toast");
Toast = this.attributes.toast.export;
}
const promises = [];
for (const key in settings)
{
if (settings[key] === true && key !== "toast")
{
const promise = this.fetchByKey(key);
if (promise)
{
promises.push(promise);
}
}
Promise.all(promises).then(() =>
{
this.applySettingsWidgets();
resolve();
});
});
}
await Promise.all(promises);
this.applySettingsWidgets();
saveSettings(settings);
}
applyComponent(key, text)
{
@ -1306,20 +1308,15 @@
}
}
loadResources();
loadSettings();
const resources = new ResourceManager();
if (settings.toast)
try
{
resources.fetchByKey("toast").then(() =>
{
Toast = resources.attributes.toast.export;
resources.fetch().then(() => saveSettings(settings));
});
loadResources();
loadSettings();
const resources = new ResourceManager();
resources.fetch().catch(error => logError(error));
}
else
catch (error)
{
resources.fetch().then(() => saveSettings(settings));
logError(error);
}
})(window.jQuery.noConflict(true));

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved
// @version 1.5.39
// @version 1.5.40
// @description 增强哔哩哔哩Web端体验: 修复界面瑕疵, 删除广告, 使用夜间模式浏览, 下载视频或视频封面, 以及增加对触屏设备的支持等.
// @author Grant Howard, Coulomb-G
// @copyright 2018, Grant Howrad (https://github.com/the1812)
@ -58,6 +58,7 @@
autoLightOff: false,
downloadDanmaku: false,
useCache: true,
toastInternalError: false,
cache: {},
};
const fixedSettings = {
@ -72,6 +73,14 @@
latestVersionLink: "https://github.com/the1812/Bilibili-Evolved/raw/master/bilibili-evolved.user.js",
currentVersion: GM_info.script.version,
};
function logError(message)
{
if (settings.toastInternalError)
{
Toast.error(message, "错误");
}
console.error(message);
}
function loadSettings()
{
for (const key in settings)
@ -343,6 +352,7 @@
],
displayNames: {
toast: "显示消息",
toastInternalError: "显示内部错误消息",
},
},
removeVideoTopMask: {
@ -1070,7 +1080,7 @@
const style = this.text;
if (style === null)
{
console.error("Attempt to get style which is not downloaded.");
logError("Attempt to get style which is not downloaded.");
}
let attributes = `id='${id}'`;
if (this.priority !== undefined)
@ -1146,69 +1156,61 @@
settings.brightness = this.color.brightness;
settings.filterInvert = this.color.filterInvert;
}
fetchByKey(key)
async fetchByKey(key)
{
const resource = Resource.all[key];
if (!resource)
{
return null;
}
const promise = resource.download();
const text = await resource.download().catch(reason =>
{
console.error(`Download error, XHR status: ${reason}`);
Toast.error(`无法下载组件<span>${Resource.all[key].displayName}</span>`, "错误");
});
resource.dependencies
.filter(it => it.type.name === "script")
.forEach(it => this.fetchByKey(it.key));
return new Promise(resolve =>
{
promise.then(text =>
resource.styles
.filter(it => it.condition !== undefined ? it.condition() : true)
.forEach(it =>
{
resource.styles
.filter(it => it.condition !== undefined ? it.condition() : true)
.forEach(it =>
{
const important = typeof it === "object" ? it.important : false;
const key = typeof it === "object" ? it.key : it;
if (important)
{
this.applyImportantStyle(key);
}
else
{
this.applyStyle(key);
}
});
this.applyComponent(key, text);
resolve();
}).catch(reason =>
{
// download error
console.error(`Download error, XHR status: ${reason}`);
Toast.error(`无法下载组件<span>${Resource.all[key].displayName}</span>`, "错误");
});
});
}
fetch()
{
return new Promise(resolve =>
{
this.validateCache();
const promises = [];
for (const key in settings)
{
if (settings[key] === true && key !== "toast")
const important = typeof it === "object" ? it.important : false;
const key = typeof it === "object" ? it.key : it;
if (important)
{
const promise = this.fetchByKey(key);
if (promise)
{
promises.push(promise);
}
this.applyImportantStyle(key);
}
else
{
this.applyStyle(key);
}
});
this.applyComponent(key, text);
}
async fetch()
{
this.validateCache();
if (settings.toast === true)
{
await this.fetchByKey("toast");
Toast = this.attributes.toast.export;
}
const promises = [];
for (const key in settings)
{
if (settings[key] === true && key !== "toast")
{
const promise = this.fetchByKey(key);
if (promise)
{
promises.push(promise);
}
}
Promise.all(promises).then(() =>
{
this.applySettingsWidgets();
resolve();
});
});
}
await Promise.all(promises);
this.applySettingsWidgets();
saveSettings(settings);
}
applyComponent(key, text)
{
@ -1306,20 +1308,15 @@
}
}
loadResources();
loadSettings();
const resources = new ResourceManager();
if (settings.toast)
try
{
resources.fetchByKey("toast").then(() =>
{
Toast = resources.attributes.toast.export;
resources.fetch().then(() => saveSettings(settings));
});
loadResources();
loadSettings();
const resources = new ResourceManager();
resources.fetch().catch(error => logError(error));
}
else
catch (error)
{
resources.fetch().then(() => saveSettings(settings));
logError(error);
}
})(window.jQuery.noConflict(true));

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<div class="gui-settings-panel"><div class="gui-settings-box"><div class="gui-settings-header"><span class="gui-settings-title">设置</span><svg class="gui-settings-close" viewBox="0 0 24 24"><path/></svg></div><div class="gui-settings-content"><ul><category>视频与直播</category><li class="indent-0"><label><span class="gui-settings-dropdown-span">默认播放器模式</span><div class="gui-settings-dropdown popup"><input readonly type="text" spellcheck="false" key="defaultPlayerMode"><ul></ul></div></label></li><checkbox indent="0" key="downloadDanmaku" dependencies=""></checkbox><checkbox indent="0" key="autoLightOff" dependencies=""></checkbox><checkbox indent="0" key="expandDanmakuList" dependencies=""></checkbox><checkbox indent="0" key="harunaScale" dependencies=""></checkbox><checkbox indent="0" key="removeLiveWatermark" dependencies=""></checkbox><checkbox indent="0" key="removeVideoTopMask" dependencies=""></checkbox><checkbox indent="0" key="blurVideoControl" dependencies=""></checkbox><checkbox indent="0" key="customControlBackground" dependencies=""></checkbox><textbox indent="1" key="customControlBackgroundOpacity" dependencies="customControlBackground"></textbox><category>样式</category><li class="indent-0"><label class="gui-settings-textbox-container"><span>主题颜色</span><div class="custom-color-preview"><div class="predefined-colors popup"><div class="predefined-colors-grid"></div></div></div><input key="customStyleColor" dependencies="" spellcheck="false" type="text"/></label></li><checkbox indent="0" key="useNewStyle" dependencies=""></checkbox><textbox indent="1" key="blurBackgroundOpacity" dependencies="useNewStyle"></textbox><checkbox indent="0" key="useDarkStyle" dependencies=""></checkbox><checkbox indent="0" key="darkSchedule" dependencies=""></checkbox><textbox indent="1" key="darkScheduleStart" dependencies="darkSchedule"></textbox><textbox indent="1" key="darkScheduleEnd" dependencies="darkSchedule"></textbox><checkbox indent="0" key="overrideNavBar" dependencies=""></checkbox><checkbox indent="1" key="showBanner" dependencies="overrideNavBar"></checkbox><checkbox indent="0" key="forceWide" dependencies=""></checkbox><textbox indent="1" key="forceWideMinWidth" dependencies="forceWide"></textbox><category>工具</category><checkbox indent="0" key="removeAds" dependencies=""></checkbox><checkbox indent="0" key="watchLaterRedirect" dependencies=""></checkbox><checkbox indent="0" key="hideTopSearch" dependencies=""></checkbox><checkbox indent="0" key="fullTweetsTitle" dependencies=""></checkbox><category>触摸优化</category><checkbox indent="0" key="touchNavBar" dependencies=""></checkbox><checkbox indent="0" key="touchVideoPlayer" dependencies=""></checkbox><checkbox indent="1" key="touchVideoPlayerAnimation" dependencies="touchVideoPlayer"></checkbox><checkbox indent="1" key="touchVideoPlayerDoubleTapControl" dependencies="touchVideoPlayer"></checkbox><category>其他</category><checkbox indent="0" key="toast" dependencies=""></checkbox><checkbox indent="0" key="blurSettingsPanel" dependencies=""></checkbox><checkbox indent="0" key="useCache" dependencies=""></checkbox></ul></div></div></div>
<div class="gui-settings-panel"><div class="gui-settings-box"><div class="gui-settings-header"><span class="gui-settings-title">设置</span><svg class="gui-settings-close" viewBox="0 0 24 24"><path/></svg></div><div class="gui-settings-content"><ul><category>视频与直播</category><li class="indent-0"><label><span class="gui-settings-dropdown-span">默认播放器模式</span><div class="gui-settings-dropdown popup"><input readonly type="text" spellcheck="false" key="defaultPlayerMode"><ul></ul></div></label></li><checkbox indent="0" key="downloadDanmaku" dependencies=""></checkbox><checkbox indent="0" key="autoLightOff" dependencies=""></checkbox><checkbox indent="0" key="expandDanmakuList" dependencies=""></checkbox><checkbox indent="0" key="harunaScale" dependencies=""></checkbox><checkbox indent="0" key="removeLiveWatermark" dependencies=""></checkbox><checkbox indent="0" key="removeVideoTopMask" dependencies=""></checkbox><checkbox indent="0" key="blurVideoControl" dependencies=""></checkbox><checkbox indent="0" key="customControlBackground" dependencies=""></checkbox><textbox indent="1" key="customControlBackgroundOpacity" dependencies="customControlBackground"></textbox><category>样式</category><li class="indent-0"><label class="gui-settings-textbox-container"><span>主题颜色</span><div class="custom-color-preview"><div class="predefined-colors popup"><div class="predefined-colors-grid"></div></div></div><input key="customStyleColor" dependencies="" spellcheck="false" type="text"/></label></li><checkbox indent="0" key="useNewStyle" dependencies=""></checkbox><textbox indent="1" key="blurBackgroundOpacity" dependencies="useNewStyle"></textbox><checkbox indent="0" key="useDarkStyle" dependencies=""></checkbox><checkbox indent="0" key="darkSchedule" dependencies=""></checkbox><textbox indent="1" key="darkScheduleStart" dependencies="darkSchedule"></textbox><textbox indent="1" key="darkScheduleEnd" dependencies="darkSchedule"></textbox><checkbox indent="0" key="overrideNavBar" dependencies=""></checkbox><checkbox indent="1" key="showBanner" dependencies="overrideNavBar"></checkbox><checkbox indent="0" key="forceWide" dependencies=""></checkbox><textbox indent="1" key="forceWideMinWidth" dependencies="forceWide"></textbox><category>工具</category><checkbox indent="0" key="removeAds" dependencies=""></checkbox><checkbox indent="0" key="watchLaterRedirect" dependencies=""></checkbox><checkbox indent="0" key="hideTopSearch" dependencies=""></checkbox><checkbox indent="0" key="fullTweetsTitle" dependencies=""></checkbox><category>触摸优化</category><checkbox indent="0" key="touchNavBar" dependencies=""></checkbox><checkbox indent="0" key="touchVideoPlayer" dependencies=""></checkbox><checkbox indent="1" key="touchVideoPlayerAnimation" dependencies="touchVideoPlayer"></checkbox><checkbox indent="1" key="touchVideoPlayerDoubleTapControl" dependencies="touchVideoPlayer"></checkbox><category>其他</category><checkbox indent="0" key="toast" dependencies=""></checkbox><checkbox indent="1" key="toastInternalError" dependencies="toast"></checkbox><checkbox indent="0" key="blurSettingsPanel" dependencies=""></checkbox><checkbox indent="0" key="useCache" dependencies=""></checkbox></ul></div></div></div>

View File

@ -61,6 +61,7 @@
<checkbox indent="1" key="touchVideoPlayerDoubleTapControl" dependencies="touchVideoPlayer"></checkbox>
<category>其他</category>
<checkbox indent="0" key="toast" dependencies=""></checkbox>
<checkbox indent="1" key="toastInternalError" dependencies="toast"></checkbox>
<checkbox indent="0" key="blurSettingsPanel" dependencies=""></checkbox>
<checkbox indent="0" key="useCache" dependencies=""></checkbox>
</ul>

View File

@ -1 +1 @@
1.5.39
1.5.40

View File

@ -121,7 +121,7 @@
}
else
{
console.error("Cancel Download Failed: forEach in this.workingXhr not found.");
logError("Cancel Download Failed: forEach in this.workingXhr not found.");
}
}
downloadFragment(fragment)