[WIP]👹dpz Fork

    @@ -1,23 +1,29 @@ /* * @title 👹dpz - * @description X-platform Daily Portal Z Eternity in Hell -- Mugen Jigoku; Avici Hell - * @include http://portal.nifty.com/* - * @license MIT License https://opensource.org/licenses/MIT + * @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 */ - /* mobile Chrome 66+ / Firefox 57+ / Safari 11.1+ - javascript:(function(){'portal.nifty.com'!==location.hostname&&(location.href='http://portal.nifty.com');var a=new AbortController,b=a.signal,c=5000;b.onabort=function(){window.alert('\uD83D\uDCE1timeout: '+c/1e3+' sec elapsed')};var d=setTimeout(function(){return a.abort()},c);fetch('http://portal.nifty.com/cs/catalog/portal_headline/random/1.htm',{signal:b,referrer:'no-referrer'}).then(function(f){return f.ok&&200===f.status?f.url:Promise.reject(new Error(f))}).then(function(f){location.href=f}).catch(function(f){b.aboted||window.alert('\u26A0\uFE0F'+f)}).finally(function(){return clearTimeout(d)})})(); + // WIP not working yet + + // `http://` version + // http://let.hatelabo.jp/noromanba/let/hJmc9ZLviM12 + + /* mobile + */ // minified w/ Babili c.f. // https://babeljs.io/repl/ - // TODO handle https + // partial-https handling hell (() => { 'use strict'; if (location.hostname !== 'portal.nifty.com') { - location.href = 'http://portal.nifty.com'; + location.href = 'https://portal.nifty.com'; } // timeout
    @@ -33,28 +39,55 @@ }; const timer = setTimeout(() => controller.abort(), TIMEOUT); - // XXX `redirect: 'manual'` for avoid Mixed-Content and CORS, but not worked - // so request was blocked // from pop-up - // http://portal.nifty.com/component/jigoku_pop.htm + // https://portal.nifty.com/component/jigoku_pop.htm // XXX API always returns `Location: http://...` in response header - const RANDOM_API = 'http://portal.nifty.com/cs/catalog/portal_headline/random/1.htm'; - - fetch(RANDOM_API, { + 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', - }).then(res => { + 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)); } - return res.url; + */ + //const url = new URL(res.url); + //url.protocol = 'https://'; + //return url; + return res.url; }).then(url => { - location.href = 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", + // }
  • /*
     * @title 👹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 です。