[?]ががっとリストに追加

    @@ -21,15 +21,25 @@ h = location.href.match(/web\/timelines\/list\/(\d+)/), t = h ? v + 'lists/' + h[1] + '/accounts' : 0, l = [], + d, p = prompt('検索語', '@mstdn.maud.io') ) => { - while (n && t) { + if (!t) { + + alert('リストを開いてください'); + return; + + } + + d = await fetch(t, a).then(r => r.json()); + + while (n) { await fetch(n, a).then(r => (( n = (r.headers.has('Link') && (h = r.headers.get('Link').match(/<(.+?)>; rel="next"/))) ? h[1] : 0 ), r.json())).then(j => ( - l = l.concat(j.filter ? j.filter(i => JSON.stringify(i).includes(p)) : []) + l = l.concat(j.filter ? j.filter(i => (JSON.stringify(i).includes(p) && !d.find(k => k.id == i.id))) : []) )); console.log(l.length, n); await s(); @@ -42,4 +52,5 @@ method: 'POST', body: JSON.stringify({ account_ids: l.map(i => i.id) }) })).then(r => r.json()).then(console.log).catch(console.error); + })();
  • /*
     * @title [?]ががっとリストに追加
     * @description 特定のワードに引っかかる人をまとめてリストに追加します。追加したいリストを開いて実行してください。
     * @include *
     * @license MIT License
     * @javascript_url
     */
    
    // @include https://*/web/timelines/list/* くらい
    
    void (async (
     s = _ => new Promise(r => setTimeout(r, 2000)),
     m = JSON.parse(document.querySelector('#initial-state').textContent).meta,
     v = 'https://' + location.host + '/api/v1/',
     n = m ? v + 'accounts/' + m.me + '/following?limit=80' : 0,
     a = m ? { headers: {
      Authorization: 'Bearer ' + m.access_token,
      Accept: 'application/json',
      'Content-Type': 'application/json'
     } } : {},
     h = location.href.match(/web\/timelines\/list\/(\d+)/),
     t = h ? v + 'lists/' + h[1] + '/accounts' : 0,
     l = [],
     d,
     p = prompt('検索語', '@mstdn.maud.io')
    ) => {
    
    	if (!t) {
    
    		alert('リストを開いてください');
    		return;
    
    	}
    
    	d = await fetch(t, a).then(r => r.json());
    
    	while (n) {
    
    		await fetch(n, a).then(r => ((
    			n = (r.headers.has('Link') && (h = r.headers.get('Link').match(/<(.+?)>; rel="next"/))) ? h[1] : 0
    		), r.json())).then(j => (
    			l = l.concat(j.filter ? j.filter(i => (JSON.stringify(i).includes(p) && !d.find(k => k.id == i.id))) : [])
    		));
    		console.log(l.length, n);
    		await s();
    
    	}
    
    	console.log(l.map(i => i.id));
    
    	await fetch(t, Object.assign(a, {
    	 method: 'POST',
    	 body: JSON.stringify({ account_ids: l.map(i => i.id) })
    	})).then(r => r.json()).then(console.log).catch(console.error);
    
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2019/02/11 09:28:19 - 2019-02-11
  2. 2018/02/07 11:19:11 - 2018-02-07
  3. 2018/02/07 11:16:22 - 2018-02-07
  4. 2018/02/07 11:16:07 - 2018-02-07