Remove downloadText calls

This commit is contained in:
the1812 2019-03-31 14:05:06 +08:00
parent 76090e58c4
commit 77231e25c2
12 changed files with 29 additions and 25 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

@ -974,7 +974,7 @@ class Resource
this.text = cache; this.text = cache;
resolve(cache); resolve(cache);
} }
downloadText(this.url).then(text => Ajax.getText(this.url).then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);
if (text === null) if (text === null)
@ -997,7 +997,7 @@ class Resource
} }
else else
{ {
downloadText(this.url) Ajax.getText(this.url)
.then(text => .then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);

View File

@ -974,7 +974,7 @@ class Resource
this.text = cache; this.text = cache;
resolve(cache); resolve(cache);
} }
downloadText(this.url).then(text => Ajax.getText(this.url).then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);
if (text === null) if (text === null)
@ -997,7 +997,7 @@ class Resource
} }
else else
{ {
downloadText(this.url) Ajax.getText(this.url)
.then(text => .then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);

View File

@ -36,7 +36,7 @@ style\simplify-liveroom\simplify-liveroom.js|397DA0535B40AFCD85426767ECAA6101CEC
style\tweets.css|A4F3590FC4A0C05FA06659AF142293A3D1FE09D0 style\tweets.css|A4F3590FC4A0C05FA06659AF142293A3D1FE09D0
touch\combo-like.js|3140FCDD2FAA19AD54BB7BE3886C20DF1BC617B2 touch\combo-like.js|3140FCDD2FAA19AD54BB7BE3886C20DF1BC617B2
touch\player\touch-player.css|12B4618CFA4A140463FF00CC1720C2785D6C3D65 touch\player\touch-player.css|12B4618CFA4A140463FF00CC1720C2785D6C3D65
touch\player\touch-player.js|F3F502CF2D01CC1537BBC15D89607AB474AFFEF3 touch\player\touch-player.js|2D41DE35BFB44CA3C0FD9E31569EE314E12A9A03
touch\touch-navbar.js|800A367309F6DC2710F61AF4A79BB63D4A6F413D touch\touch-navbar.js|800A367309F6DC2710F61AF4A79BB63D4A6F413D
utils\about\about.css|7039CA8905E0CACF72B69AF535A92B61C598C980 utils\about\about.css|7039CA8905E0CACF72B69AF535A92B61C598C980
utils\about\about.html|E4DB0B7786D8CFC71E16008564850F60681A59B7 utils\about\about.html|E4DB0B7786D8CFC71E16008564850F60681A59B7
@ -101,7 +101,7 @@ video\player-focus.js|1A23319B3F0413B69104B71AC10DBF8B6B6E5ECA
video\skip-charge-list\skip-charge-list.css|5A81D57BB1077D32100BF6B3C57CAED65AF2345B video\skip-charge-list\skip-charge-list.css|5A81D57BB1077D32100BF6B3C57CAED65AF2345B
video\skip-charge-list\skip-charge-list.js|A45110BFF47DA5F04F17138EE5CE2483E6F9CDAE video\skip-charge-list\skip-charge-list.js|A45110BFF47DA5F04F17138EE5CE2483E6F9CDAE
video\title.js|77F14B26A6183441D0E9C322DCB28BCE0D1AAC65 video\title.js|77F14B26A6183441D0E9C322DCB28BCE0D1AAC65
video\video-info.js|9EF4EF06B89F61245F613C3E55DF85C03BBDD17D video\video-info.js|DDDBDFBC3888608CF5A905560F3D70A9E6CD5A94
video\view-cover\image-viewer.css|7075C4B76A8F1BDB1050B31372925696CB4A95F9 video\view-cover\image-viewer.css|7075C4B76A8F1BDB1050B31372925696CB4A95F9
video\view-cover\image-viewer.html|C199EFDE5C7A90C434554F2D73B54AB0750739EC video\view-cover\image-viewer.html|C199EFDE5C7A90C434554F2D73B54AB0750739EC
video\view-cover\view-cover.js|7B3365E5B3C585F391FE519EF44E33C0CF4FE2E7 video\view-cover\view-cover.js|2563F07C0A7DD03A6347E8C2D40B2C1B43271FC6

View File

@ -72,7 +72,7 @@ export class Resource
this.text = cache; this.text = cache;
resolve(cache); resolve(cache);
} }
downloadText(this.url).then(text => Ajax.getText(this.url).then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);
if (text === null) if (text === null)
@ -95,7 +95,7 @@ export class Resource
} }
else else
{ {
downloadText(this.url) Ajax.getText(this.url)
.then(text => .then(text =>
{ {
this.text = this.type.preprocessor(text); this.text = this.type.preprocessor(text);

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
(()=>{return(t,i)=>{class e{constructor(t){this.aid=t}async fetchInfo(){const t=JSON.parse(await downloadText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`));if(t.code!==0){throw new Error(t.message)}const i=t.data;this.cid=i.cid;this.pageCount=i.videos;this.coverUrl=i.pic;this.tagId=i.tid;this.tagName=i.tname;this.title=i.title;this.description=i.desc;this.up={uid:i.owner.mid,name:i.owner.name,faceUrl:i.owner.face};this.pages=i.pages.map(t=>{return{cid:t.cid,title:t.part,pageNumber:t.page}});return this}async fetchDanmaku(){this.danmaku=new s(this.cid);return this.danmaku.fetchInfo()}}class a{constructor(t,i){this.text=t;this.p=i}}class s{constructor(t){this.cid=t}async fetchInfo(){const t=await downloadText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=t;const i=(new DOMParser).parseFromString(t,"application/xml").documentElement;this.xml=i;this.danmakus=[].map.call(i.querySelectorAll("d[p]"),t=>{return new a(t.innerHTML,t.getAttribute("p"))})}}class n{constructor(t){this.ep=t;this.videos=[]}async fetchInfo(){const t=await downloadText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const i=JSON.parse(t.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=i.mediaInfo.title;this.cover=i.mediaInfo.cover;this.squareCover=i.mediaInfo.square_cover;this.aid=i.epInfo.aid;this.cid=i.epInfo.cid;this.videos=i.epList.map(async t=>{return{title:t.index_title,aid:t.aid,cid:t.cid,info:await new e(t.aid).fetchInfo()}});return this}}return{export:{VideoInfo:e,BangumiInfo:n,Danmaku:a,DanmakuInfo:s}}}})(); (()=>{return(t,i)=>{class e{constructor(t){this.aid=t}async fetchInfo(){const t=JSON.parse(await Ajax.getText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`));if(t.code!==0){throw new Error(t.message)}const i=t.data;this.cid=i.cid;this.pageCount=i.videos;this.coverUrl=i.pic;this.tagId=i.tid;this.tagName=i.tname;this.title=i.title;this.description=i.desc;this.up={uid:i.owner.mid,name:i.owner.name,faceUrl:i.owner.face};this.pages=i.pages.map(t=>{return{cid:t.cid,title:t.part,pageNumber:t.page}});return this}async fetchDanmaku(){this.danmaku=new s(this.cid);return this.danmaku.fetchInfo()}}class a{constructor(t,i){this.text=t;this.p=i}}class s{constructor(t){this.cid=t}async fetchInfo(){const t=await Ajax.getText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);this.rawXML=t;const i=(new DOMParser).parseFromString(t,"application/xml").documentElement;this.xml=i;this.danmakus=[].map.call(i.querySelectorAll("d[p]"),t=>{return new a(t.innerHTML,t.getAttribute("p"))})}}class n{constructor(t){this.ep=t;this.videos=[]}async fetchInfo(){const t=await Ajax.getText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);const i=JSON.parse(t.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);this.title=i.mediaInfo.title;this.cover=i.mediaInfo.cover;this.squareCover=i.mediaInfo.square_cover;this.aid=i.epInfo.aid;this.cid=i.epInfo.cid;this.videos=i.epList.map(async t=>{return{title:t.index_title,aid:t.aid,cid:t.cid,info:await new e(t.aid).fetchInfo()}});return this}}return{export:{VideoInfo:e,BangumiInfo:n,Danmaku:a,DanmakuInfo:s}}}})();

View File

@ -1 +1 @@
(()=>{return(e,t)=>{const{VideoInfo:i}=t.import("video-info");const{getFriendlyTitle:n}=t.import("title");class o{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createContainer()}this.viewer=$(".image-viewer-container");this.downloadImage()}createContainer(){$("body").append((t.data.imageViewerDom||t.data.imageViewerHtml).text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=n();const i=URL.createObjectURL(e.response);if(this.imageData){URL.revokeObjectURL(this.imageData)}this.imageData=i;this.viewer.find(".download").attr("href",i).attr("download",t+this.url.substring(this.url.lastIndexOf(".")));this.viewer.find(".copy-link").on("click",()=>GM_setClipboard(this.url));this.viewer.find(".new-tab").attr("href",this.url);this.viewer.find(".image").prop("src",i)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}return(()=>{if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new i(e);await t.fetchInfo();return t.coverUrl}let t=new o(await e());$("#view-cover").on("click",()=>{t.show()});const n=async()=>{t=new o(await e())};if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const i=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const n=await downloadText(i);const s=JSON.parse(n).data.cover;const a=new o(s);$("#view-cover").on("click",()=>{a.show()})}}}}}})()}})(); (()=>{return(e,t)=>{const{VideoInfo:i}=t.import("video-info");const{getFriendlyTitle:n}=t.import("title");class o{constructor(e){this.url=e;if($(".image-viewer").length===0){this.createContainer()}this.viewer=$(".image-viewer-container");this.downloadImage()}createContainer(){$("body").append((t.data.imageViewerDom||t.data.imageViewerHtml).text);$(".image-viewer-container .close").on("click",()=>this.hide());t.applyStyle("imageViewerStyle")}downloadImage(){const e=new XMLHttpRequest;e.open("GET",this.url.replace("http:","https:"),true);e.responseType="blob";e.onload=(()=>{const t=n();const i=URL.createObjectURL(e.response);if(this.imageData){URL.revokeObjectURL(this.imageData)}this.imageData=i;this.viewer.find(".download").attr("href",i).attr("download",t+this.url.substring(this.url.lastIndexOf(".")));this.viewer.find(".copy-link").on("click",()=>GM_setClipboard(this.url));this.viewer.find(".new-tab").attr("href",this.url);this.viewer.find(".image").prop("src",i)});e.send()}show(){this.viewer.addClass("opened")}hide(){this.viewer.removeClass("opened")}}return(()=>{if($("meta[itemprop='image'],meta[property='og:image']").length>0){return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>(unsafeWindow||window).aid);return Boolean(e)},success:async()=>{async function e(){const e=(unsafeWindow||window).aid;const t=new i(e);await t.fetchInfo();return t.coverUrl}let t=new o(await e());$("#view-cover").on("click",()=>{t.show()});const n=async()=>{t=new o(await e())};if(Observer.videoChange){Observer.videoChange(n)}else{Observer.childList("#bofqi",n)}}}}}else{return{widget:{content:`\n <button\n class="gui-settings-flat-button"\n id="view-cover">\n <i class="icon-view"></i>\n <span>查看封面</span>\n </button>`,condition:async()=>{const e=await SpinQuery.select(()=>document.querySelector(".header-info-ctnr .room-cover"));return Boolean(e)},success:async()=>{const e=$(".header-info-ctnr .room-cover");const t=e.attr("href").match(/space\.bilibili\.com\/([\d]+)/);if(t&&t[1]){const e=t[1];const i=`https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${e}`;const n=await Ajax.getText(i);const s=JSON.parse(n).data.cover;const a=new o(s);$("#view-cover").on("click",()=>{a.show()})}}}}}})()}})();

View File

@ -286,9 +286,13 @@ class VideoShot
} }
getVideoshot(currentTime, done) getVideoshot(currentTime, done)
{ {
if (!(this.aid && this.cid))
{
return;
}
if (!this.cidData) if (!this.cidData)
{ {
downloadText(`https://api.bilibili.com/x/player/videoshot?aid=${this.aid}&cid=${this.cid}&index=1`).then(response => Ajax.getText(`https://api.bilibili.com/x/player/videoshot?aid=${this.aid}&cid=${this.cid}&index=1`).then(response =>
{ {
this.cidData = JSON.parse(response).data; this.cidData = JSON.parse(response).data;
this.getVideoshot(currentTime, done); this.getVideoshot(currentTime, done);

View File

@ -6,7 +6,7 @@ export class VideoInfo
} }
async fetchInfo() async fetchInfo()
{ {
const json = JSON.parse(await downloadText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`)); const json = JSON.parse(await Ajax.getText(`https://api.bilibili.com/x/web-interface/view?aid=${this.aid}`));
if (json.code !== 0) if (json.code !== 0)
{ {
throw new Error(json.message); throw new Error(json.message);
@ -56,7 +56,7 @@ export class DanmakuInfo
} }
async fetchInfo() async fetchInfo()
{ {
const xml = await downloadText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`); const xml = await Ajax.getText(`https://api.bilibili.com/x/v1/dm/list.so?oid=${this.cid}`);
this.rawXML = xml; this.rawXML = xml;
const dom = new DOMParser().parseFromString(xml, "application/xml").documentElement; const dom = new DOMParser().parseFromString(xml, "application/xml").documentElement;
@ -76,7 +76,7 @@ export class BangumiInfo
} }
async fetchInfo() async fetchInfo()
{ {
const data = await downloadText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`); const data = await Ajax.getText(`https://www.bilibili.com/bangumi/play/ep${this.ep}/`);
const json = JSON.parse(data.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]); const json = JSON.parse(data.match(/window\.__INITIAL_STATE__=(.*);\(function\(\){/)[1]);
this.title = json.mediaInfo.title; this.title = json.mediaInfo.title;
this.cover = json.mediaInfo.cover; this.cover = json.mediaInfo.cover;

View File

@ -126,7 +126,7 @@ export default (() =>
{ {
const uid = match[1]; const uid = match[1];
const url = `https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${uid}`; const url = `https://api.live.bilibili.com/room/v1/Room/getRoomInfoOld?mid=${uid}`;
const text = await downloadText(url); const text = await Ajax.getText(url);
const coverUrl = JSON.parse(text).data.cover; const coverUrl = JSON.parse(text).data.cover;
const imageViewer = new ImageViewer(coverUrl); const imageViewer = new ImageViewer(coverUrl);
$("#view-cover").on("click", () => $("#view-cover").on("click", () =>