Created
May 6, 2018 12:34
-
-
Save imcuttle/c345279c6b7a690a5722a8506ba8f1a9 to your computer and use it in GitHub Desktop.
Markme leancloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name New Script | |
// @namespace video | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
// | |
function load(src) { | |
return new Promise((resolve, reject) => { | |
let script = document.createElement('script') | |
script.src = src | |
script.onload = resolve | |
script.onerror = reject | |
document.head.appendChild(script) | |
}) | |
} | |
window.addEventListener('load', function (evt) { | |
// http://cdn1.lncld.net/static/js/3.6.8/av-min.js | |
// https://unpkg.com/markme-leancloud@0.0.2/lib/index.umd.min.js | |
// https://unpkg.com/markme@0.0.2/lib/index.umd.min.js | |
Promise | |
.all([ | |
load('//cdn1.lncld.net/static/js/3.6.8/av-min.js'), | |
load('//unpkg.com/markme') | |
]) | |
.then(() => load('//unpkg.com/markme-leancloud')) | |
.then(() => { | |
let opt = { | |
highlight: { | |
disableDefaultClick: false | |
}, | |
AVOptions: { | |
appId: 'YY0ajzbgR0NlSODErX04ya3E-gzGzoHsz', | |
appKey: 'KRSsdRICas0xDPmnO9znHY5E' | |
} | |
} | |
let m = MarkmeLeancloud(document.body, opt) | |
let t | |
if (window.history) { | |
var pushState = history.pushState; | |
history.pushState = function(state) { | |
if (t) { | |
clearTimeout(t) | |
t = null | |
} | |
// wait for page render | |
t = setTimeout(() => { | |
m = MarkmeLeancloud(document.body, opt) | |
t = null | |
}, 1000) | |
// ... whatever else you want to do | |
// maybe call onhashchange e.handler | |
return pushState.apply(history, arguments); | |
} | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment