youtube2hatena

    
      
  • // ==UserScript==
    // @title        youtube2hatena
    // @name         youtube2hatena
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match        https://www.youtube.com/*
    // @grant        none
    // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
    // ==/UserScript==
    var result2 = document.evaluate('id("search-form")', document, null, 7, null);
    result2.snapshotItem(0).insertAdjacentHTML('afterend', '<input type="button" value="メモ" id="draft">');
    $(function () {
      $('#draft').click(function () {
        localStorage.setItem("n_url", location.href);
        history.pushState(null, null, "/channel/");
        document.body.innerHTML = "";
        document.body.insertAdjacentHTML("beforeend", "<textarea>戻るボタンなどのブラウザバックで元のページに戻ります</textarea><br><input type='button' value='save'><input type='button' value='load'><input type='button' value='hatena'>");
        var result2 = document.evaluate('//input', document, null, 7, null);
        result2.snapshotItem(0).addEventListener('click', sample, false);
        result2.snapshotItem(1).addEventListener('click', sample2, false);
        result2.snapshotItem(2).addEventListener('click', sample3, false);
    
        function sample() {
          var result3 = document.evaluate('//textarea', document, null, 7, null);
          localStorage.setItem('draft', result3.snapshotItem(0).value);
          alert("保存しました");
        }
    
        function sample2() {
          var result3 = document.evaluate('//textarea', document, null, 7, null);
          var draft = localStorage.getItem('draft');
          result3.snapshotItem(0).value = draft;
          alert("ロードしました");
        }
    
        function sample3() {
          var result3 = document.evaluate('//textarea', document, null, 7, null);
          var r1 = /https\:\/\//gi;
          var r2 = /(\[.+)\n/gi;
          var r3 = /\&t\=\d+s/gi;
          result3.snapshotItem(0).value = result3.snapshotItem(0).value.replace(r1, '[https://');
          result3.snapshotItem(0).value = result3.snapshotItem(0).value.replace(r2, '$1:embed:cite]\n');
          result3.snapshotItem(0).value = result3.snapshotItem(0).value.replace(r3, '');
          alert("はてな記法に置き換えました");
        }
        window.addEventListener('popstate', function (event) {
          location.href = localStorage.getItem("n_url");
        });
      }, );
    });
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/12/03 14:08:27 - 2018-12-03