// ==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");
});
}, );
});