Last active
August 29, 2015 14:09
-
-
Save Qofar/6c56875bcdc86f32e77f to your computer and use it in GitHub Desktop.
feedlyのSaved for laterをGoogle Bookmarksに保存するGreasemonkeyスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name feedly_gbsaver | |
// @description Save pins into Google Bookmarks | |
// @namespace http://ma.la/ | |
// @include http://feedly.com/* | |
// @include https://feedly.com/* | |
// @grant GM_xmlhttpRequest | |
// @version 1.0.0 | |
// ==/UserScript== | |
// http://la.ma.la/blog/diary_200605070200.htm | |
(function(){ | |
var regex = /<smh:signature>(.+)<\/smh:signature>/; | |
var sig = ""; | |
function showDialog(msg){ | |
var gbDialog = document.getElementById("gbDialog"); | |
if(!gbDialog){ | |
var div = document.createElement("div"); | |
div.id = "gbDialog"; | |
div.style.cssText = "background-color: #333333; display: none; opacity: 0.8; color: #fff; top: 50%; left: 50%; max-width: 600px; width: 600px; height: 50px; margin: -200px 0px 0px -200px; padding: 20px; text-align: center; font-size : 16px; font-weight: bold; z-index: 99999; position: fixed; -moz-user-select: none; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;"; | |
document.body.appendChild(div); | |
gbDialog = div; | |
} | |
gbDialog.textContent= msg; | |
gbDialog.style.display = "block"; | |
window.setTimeout(function(){ | |
gbDialog.style.display = "none"; | |
}, 1000); | |
} | |
// customize your label | |
function make_label(){ | |
// yyyy-mm | |
var dt = new Date; | |
var year = dt.getFullYear(); | |
var month = dt.getMonth() + 1; | |
var day = dt.getDate(); | |
function zerofill(num){ | |
return num < 10 ? "0"+num : num; | |
} | |
month = zerofill(month); | |
day = zerofill(day); | |
var ym = [year, month].join("-"); | |
// folder | |
var folder = document.querySelector("#feedlyTabsHolder .selected").parentElement.id.replace("_tab_sources",""); | |
return ["LDR",folder,ym].join(","); | |
} | |
// get sig | |
function get_Sig(){ | |
window.setTimeout(function() { | |
GM_xmlhttpRequest({ | |
method: "get", | |
url: "https://www.google.com/bookmarks/lookup?output=rss&num=10", | |
onload: function(res){ | |
if(res.status === 200 && | |
res.finalUrl.indexOf("https://www.google.com/bookmarks/") === 0 && | |
res.responseText.match(regex)){ | |
sig = new String(RegExp.$1); | |
}else{ | |
showDialog("Google Bookmarks - not login..."); | |
} | |
} | |
}) | |
}, 0); | |
} | |
get_Sig(); | |
document.addEventListener("keydown", function(e){ | |
if(e.keyCode === 83 && | |
!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey && | |
!/^input|^textarea/i.test(e.target.tagName)){ | |
var item = document.querySelector(".u100Frame.selectedEntry"); | |
if(!item) return; | |
var icons = item.getElementsByClassName("headerInfo-expanded-img"); | |
for (var i = 0, length = icons.length; i < length; i++) { | |
if(icons[i].src.indexOf("/ab-saved.png") !== -1) return; | |
} | |
var url = item.getAttribute("data-alternate-link"); | |
var title = item.getAttribute("data-title"); | |
// url = url.replace(/#.*$/, ''); | |
gb.save(url, title, make_label()); | |
} | |
},true); | |
function GBSaver(){ | |
function form_encode(param){ | |
var buf = []; | |
for(var key in param){ | |
var value = param[key]; | |
buf.push( | |
encodeURIComponent(key)+"="+ | |
encodeURIComponent(value) | |
) | |
} | |
return buf.join("&"); | |
} | |
this.save = function(url,title,label){ | |
showDialog("sending private data to Google ... "); | |
var postdata = form_encode({ | |
sig: sig, | |
bkmk: url, | |
title: title, | |
labels: label, | |
prev: "/lookup" | |
}); | |
window.setTimeout(function() { | |
GM_xmlhttpRequest({ | |
method: "post", | |
headers: {"Content-type": "application/x-www-form-urlencoded"}, | |
url: "https://www.google.com/bookmarks/mark", | |
data: postdata, | |
onload: function(res){ | |
showDialog("sending private data to Google ... done"); | |
} | |
}) | |
}, 0); | |
} | |
} | |
var gb = new GBSaver(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment