駅探で検索した電車の時間を、Googleカレンダーに予定として登録するブックマークレット
javascript: (function(){
var addzero = function(n){
if (n < 10) {
return "0" + n;
}
else {
return n + "";
}
};
var datestr = function(d){
return d.getUTCFullYear() + addzero(d.getUTCMonth() + 1) + addzero(d.getUTCDate()) + "T" + addzero(d.getUTCHours()) + addzero(d.getUTCMinutes()) + "00Z";
};
var i;
var norikae_list = document.getElementById("norikae_list");
var datecontent = norikae_list.getElementsByTagName("h2")[0];
var text = datecontent.firstChild.nodeValue;
var ems = datecontent.getElementsByTagName("em");
var year = ems[0].innerHTML;
var month = ems[1].innerHTML - 1;
var day = ems[2].innerHTML;
var maincontent;
for (i = 1; i < 6; i++) {
maincontent = document.getElementById("route" + i);
if (maincontent.getAttribute("style") === "") {
break;
}
}
var h2 = maincontent.getElementsByTagName("h2")[0];
var h2text = h2.firstChild.nodeValue;
var timecontent = h2text.match(/\d\d/g);
var shour = timecontent[0];
var smin = timecontent[1];
var ehour = timecontent[2];
var emin = timecontent[3];
var table = maincontent.getElementsByTagName("table")[1];
var times = table.getElementsByClassName("time");
var stations = table.getElementsByClassName("station_name");
var trains = table.getElementsByClassName("train");
var details = "";
for (i = 0; i < trains.length; i++) {
details += times[i * 2].textContent;
details += " ";
details += stations[i].innerHTML;
details += "<br/>";
details += times[i * 2 + 1].textContent;
details += " ";
details += trains[i].innerHTML;
details += "<br/>";
};
details += times[i * 2].textContent;
details += stations[i].innerHTML;
var start = new Date(year, month, day, shour, smin, 0);
var end = new Date(year, month, day, ehour, emin, 0);
var dates = datestr(start) + "/" + datestr(end);
var url = "https://www.google.com/calendar/event?action=TEMPLATE&text=" +
encodeURIComponent(text) +
"&dates=" +
dates +
"&details=" +
encodeURIComponent(details);
window.open(url, "_blank");
})();
社内の短縮URLのWEBサイト規制を回避するChromeの拡張機能を作った。
のですけれど、はてなダイアリーには添付できないんですね。。。
メールしてください。
社内の短縮URLのWEBサイト規制を回避するGreasemonkeyスクリプト。
うちの会社では、bit.lyとかの短縮URLを開こうとすると、Proxyのサイト規制に引っかかって表示されません。なのでそれを回避するGreasemonkyスクリプトを作りました。以下のJavaScriptをGreasemonkyスクリプトとして登録して、”ユーザスクリプトを実行するページ”をhttp://bit.ly/*とかにしておけばOK。
(function(){
var url = window.location.href;
// Callback
var callback = document.createElement('script');
callback.type = 'text/javascript';
callback.charset = 'UTF-8';
var t = document.createTextNode("var json_callback = function(r) { location.href=r[\"" + url + "\"]; };");
callback.appendChild(t);
document.body.appendChild(callback);
// JSONP
var jsonp = document.createElement('script');
jsonp.src = "http://www.longurlplease.com/api/v1.1?q=" + url + "&callback=json_callback"
jsonp.charset = "UTF-8";
document.body.appendChild(jsonp);
})();http://www.sukechan.net/archives/152/
こちらの記事を参考にさせていただきました。
Read It Laterにポストするブックマークレットの合体版
- iPhone版Googleリーダーで、今見ているエントリーをRead It Laterにポストする
- Instapaper mobilizerで見ていたページをRead It Laterにポストする
- それ以外であれば、今見ているページをそのままRead It Laterにポストする
javascript:
(function(){
var url;
var title;
if (/http:\/\/www\.google\.co\.jp\/reader\/i\//.test(location.href)) {
var expanded = document.getElementsByClassName("expanded");
var a = expanded[0].getElementsByClassName("item-title");
var link = a[0].getAttribute("href");
url = encodeURIComponent(link);
title = encodeURIComponent(a[0].innerHTML);
} else if (/http:\/\/www\.instapaper\.com\/m/.test(location.href)) {
url = location.href.substring(30);
title = encodeURIComponent(document.title);
} else {
url = encodeURIComponent(location.href);
title = encodeURIComponent(document.title);
}
location.href = "http://readitlaterlist.com/edit_process.php?url=" + url + "&title=" + title;
})();
Deliciousにポストするブックマークレットの合体版
さっき作ったブックマークレットの合体版
- iPhone版Googleリーダーで、今見ているエントリーをDeliciousにポストする
- Instapaper mobilizerで見ていたページをDeliciousにポストする
- それ以外であれば、今見ているページをそのままDeliciousにポストする
javascript: (function(){
var url;
var title;
if (/http:\/\/www\.google\.co\.jp\/reader\/i\//.test(location.href)) {
var expanded = document.getElementsByClassName("expanded");
var a = expanded[0].getElementsByClassName("item-title");
var link = a[0].getAttribute("href");
url = encodeURIComponent(link);
title = encodeURIComponent(a[0].innerHTML);
} else if (/http:\/\/www\.instapaper\.com\/m/.test(location.href)) {
url = location.href.substring(30);
title = encodeURIComponent(document.title);
} else {
url = encodeURIComponent(location.href);
title = encodeURIComponent(document.title);
}
window.open("http://m.delicious.com/save?url=" + url + "&title=" + title + "&jump=doclose");
})();
Instapaper mobilizerで見ていたページをDeliciousにポストするブックマークレット
javascript:
window.open("http://m.delicious.com/save?url=" + location.href.substring(30) + "&title=" + encodeURIComponent(document.title) + "&jump=doclose");