[WIP]?dpz
by
noromanba
2018-05-30 [2018/05/30 08:17:23]
(Forked from
?dpz by
noromanba)
[WIP] X-platform Daily Portal Z Eternity in Hell -- Mugen Jigoku; Avici Hell on https
-
/*
* @title [WIP]?dpz
* @description [WIP] X-platform Daily Portal Z Eternity in Hell -- Mugen Jigoku; Avici Hell on https
* @include https://portal.nifty.com/*
* @contributor noromanba http://let.hatelabo.jp/noromanba/let/hJmc9ZLviM12
* @license MIT License https://opensource.org/licenses/MIT
* @javascript_url
*/
// WIP not working yet
// `http://` version
// http://let.hatelabo.jp/noromanba/let/hJmc9ZLviM12
/* mobile
*/
// minified w/ Babili c.f.
// https://babeljs.io/repl/
// partial-https handling hell
(() => {
'use strict';
if (location.hostname !== 'portal.nifty.com') {
location.href = 'https://portal.nifty.com';
}
// timeout
// https://gist.github.com/noromanba/7e76cd75d15e27b102007298a8156d8f
// TBD Promise based functionize
// `AbortController` required Chrome 66+ / Firefox 57+ / Safari 11.1+ c.f.
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController
const controller = new AbortController();
const signal = controller.signal;
const TIMEOUT = 1000 * 5;
signal.onabort = () => {
window.alert('?timeout: ' + TIMEOUT / 1000 + ' sec elapsed');
};
const timer = setTimeout(() => controller.abort(), TIMEOUT);
// from pop-up
// https://portal.nifty.com/component/jigoku_pop.htm
// XXX API always returns `Location: http://...` in response header
const RANDOM_API = 'https://portal.nifty.com/cs/catalog/portal_headline/random/1.htm';
const req = new Request(RANDOM_API, {
signal,
//credentials: 'same-origin', // dpz members required?
referrer: 'no-referrer',
mode: 'same-origin',
// FIXME force https and avoid CORS/Mixed-Content c.f.
// https://sisidovski.hatenablog.com/entry/2016/10/04/011900
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
redirect: 'manual',
});
fetch(req).then(res => {
console.debug(res);
/* FIXME dangerous but can not use [:1]
if (!res.ok || res.status !== 200) {
return Promise.reject(new Error(res));
}
*/
//const url = new URL(res.url);
//url.protocol = 'https://';
//return url;
return res.url;
}).then(url => {
console.debug(url);
//location.href = url;
}).catch(err => {
if (signal.aboted) return;
window.alert('⚠️' + err);
}).finally(() => clearTimeout(timer));
})();
// DEV
//
// [^1] Request { redirect: 'manual', } do not return Response statuses c.f.
// https://fetch.spec.whatwg.org/#concept-filtered-response-opaque
// https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect
// https://fetch.spec.whatwg.org/#concept-filtered-response
// https://fetch.spec.whatwg.org/#concept-internal-response
//
// Response {
// ok: false,
// redirected: false,
// status: 0,
// statusText: "",
// type: "opaqueredirect",
// }
-
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。