Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
[general] improvements
Browse files Browse the repository at this point in the history
- [flv] faster load
- merge from hd branch
 - Update to jQuery 3.1.1
 - [background.js] fix fetch credentials
 - [background.js]refactor getDownloadLink with fetch 
 - [bilibili_injected.js] bug fix on player switching
 - [bilibili_injected.js] cache comments to avoid the same comments being loaded again
 - [ass] use opacity from biliHelper.playerConfig.opacity
 - [ass] update to tiansh/us-danmaku@e07fb80
  • Loading branch information
myfreeer committed Dec 8, 2016
1 parent 8d3aa6b commit 5b79d09
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 384 deletions.
31 changes: 17 additions & 14 deletions ABPlayer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
var ABP = {
"version": "0.8.0"
};

var parseXmlSafe = function parseXmlSafe(text) {
"use strict";
text = text.replace(/(?:[\0-\x08\x0B\f\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g, "");
if (window.DOMParser) return new window.DOMParser().parseFromString(text, "text/xml");else if (ActiveXObject) {
var activeXObject = new ActiveXObject("Microsoft.XMLDOM");
activeXObject.async = false;
activeXObject.loadXML(text);
return activeXObject;
} else throw new Error("parseXmlSafe: XML Parser Not Found.");
};
/***********************
* XMLParser
* == Licensed Under the MIT License : /LICENSING
* Copyright (c) 2012 Jim Chen ( CQZ, Jabbany )
************************/
function CommentLoader(url, xcm, callback) {
var cm = xcm;
if (callback == null)
callback = function() {
return;
};
if (typeof url == "object" && typeof url.getElementsByTagName == "function") return callback(cm.load(BilibiliParser(url)));
if (url.indexOf('data:application/xml;charset=utf-8,') === 0) return callback(cm.load(BilibiliParser(parseXmlSafe(url.substring(35)))));
var xmlhttp = null;
var retry = 0;
if (window.XMLHttpRequest) {
Expand All @@ -22,26 +34,17 @@ function CommentLoader(url, xcm, callback) {
xmlhttp.open("GET", url, true);
xmlhttp.onerror = function() {
xmlhttp.abort();
xmlhttp.open("GET", url, true);
if (retry < 3) xmlhttp.send();
retry += 1;
};
xmlhttp.ontimeout = xmlhttp.onerror;
xmlhttp.send();
var cm = xcm;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (navigator.appName == 'Microsoft Internet Explorer') {
var f = new ActiveXObject("Microsoft.XMLDOM");
f.async = false;
f.loadXML(xmlhttp.responseText);
cm.load(BilibiliParser(f));
callback();
} else {
var standarizedXML = xmlhttp.responseXML == null ? (new window.DOMParser()).parseFromString(xmlhttp.responseText.replace(/[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/g,""), "text/xml") : xmlhttp.responseXML;
cm.load(BilibiliParser(standarizedXML));
//console.log(standarizedXML);
callback();
}
var standarizedXML = xmlhttp.responseXML == null ? parseXmlSafe(xmlhttp.responseText) : xmlhttp.responseXML;
cm.load(BilibiliParser(standarizedXML));
callback();
}
}
}
Expand Down
Loading

0 comments on commit 5b79d09

Please sign in to comment.