Skip to content

Instantly share code, notes, and snippets.

@Aquei
Last active February 8, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aquei/ad875ad951f1dabcfedf to your computer and use it in GitHub Desktop.
Save Aquei/ad875ad951f1dabcfedf to your computer and use it in GitHub Desktop.
シーサイド・コミュニケーションズのウェブ配信を直接再生
// ==UserScript==
// @description シーサイド・コミュニケーションズのウェブ配信を直接再生
// @include http://seaside-c.jp/program/*
// @include http://it.seaside-c.jp/
// @name シーサイド・コミュニケーションズのウェブ配信を直接再生
// @namespace https://gist.github.com/Aquei/ad875ad951f1dabcfedf
// @version 1.0.0
// ==/UserScript==
// @license Apache v2 License <http://www.apache.org/licenses/LICENSE-2.0>
try{
const selector = `a[href$=".wax"]`;
const elm = document.querySelector(selector) || (()=>{throw "no playlist found"})();
new Promise( (resolve, reject) => {
const req = new XMLHttpRequest();
req.open('GET', elm.href, true);
req.responseType = 'document';
req.overrideMimeType('text/xml; charset=Shift_JIS');
req.onload = () => resolve(req.responseXML);
req.onError = () => reject();
req.send();
})
.then(doc => {
const ref = doc.querySelector("ref,REF");
const url = ref.getAttribute("href") || ref.getAttribute("HREF");
const title = (doc.querySelector("title") || doc.querySelector("TITLE")).textContent;
const ext = url.match(/^[^?]+\.([a-z]+)\??/)[1] || "wma";
/*
const btn = document.createElement("a");
const style = `display: inline-block;
color:black;
background-color:Gainsboro;
border: 1px black solid;
border-radius: 4px;
margin: 1em;
padding:5px;`;
btn.setAttribute("style", style);
btn.setAttribute("href", url);
btn.setAttribute("download", (title+'.'+ext).replace(/[<>:"/\\|?*]/, ''));
btn.textContent = "ダウンロード";
//追加
elm.parentNode.insertBefore(btn, elm.nextSibling);
*/
elm.setAttribute("href", url);
elm.setAttribute("download", (title+'.'+ext).replace(/[<>:"/\\|?*]/, ''));
});
}catch(err){
//throw err;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment