Skip to content

Instantly share code, notes, and snippets.

@WyohKnott
Created January 9, 2015 16:25
Show Gist options
  • Save WyohKnott/698467d7962b498bb01c to your computer and use it in GitHub Desktop.
Save WyohKnott/698467d7962b498bb01c to your computer and use it in GitHub Desktop.
Convert a Tumblelog following list to an OPML file
// ==UserScript==
// @name following2opml
// @namespace following2opml
// @description Convert a Tumblelog following list to an OPML file
// @author Wyoh
// @include https://www.tumblr.com/following
// @homepage http://wyoh.tumblr.com
// @license WTFPL — http://www.wtfpl.net/
// @version 1.0
// @grant none
// ==/UserScript==
(function () {
function initfollowing2opml() {
var e = window.jQuery;
var f2oButton = e('<div class="chrome blue big clearfix" style="text-align:center;">Convert to OPML</div>');
var f2oTextarea = e('<textarea cols=114 rows=26 style="padding:20px;margin:20px;border-color:#529ECC;border-width:2px;border-style:2px;"></textarea>');
f2oTextarea.val('<?xml version="1.0" encoding="UTF-8"?>\r\n<opml version="1.0">\r\n<head>\r\n<title>Following on Tumblr</title>\r\n</head>\r\n<body>\r\n');
var f2oAppend = function () {
e('#left_column .name a').each(function (index) {
var f2oName,
f2oURL;
f2oName = e(this).text();
f2oURL = e(this).attr('href');
f2oTextarea.val(function (index, value) {
return value + '<outline text="' + f2oName + '" title="' + f2oName + '" type="rss" xmlUrl="' + f2oURL + 'rss" htmlUrl="' + f2oURL + '"/>\r\n';
});
});
f2oProcess();
};
var f2oProcess = function () {
if (e('a.next').length) {
var f2oNext;
f2oNext = e('a.next').attr('href') + ' #left_column';
e('#left_column').load(f2oNext, function () {
f2oAppend();
});
} else {
f2oTextarea.val(function (index, value) {
return value + '</body>\r\n</opml>\r\n';
}).focus().select();
}
};
f2oButton.on('click', function () {
e(this).replaceWith(f2oTextarea);
f2oAppend();
});
f2oTextarea.on('focus', function () {
e(this).select();
}).on('click', function () {
e(this).select();
});
e('.l-content').append(f2oButton);
}
var v = '1.7.2';
if (typeof window.jQuery == 'undefined' || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement('script');
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/' + v + '/jquery.min.js';
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
initfollowing2opml()
}
};
document.getElementsByTagName('head') [0].appendChild(script)
} else {
initfollowing2opml()
}
}) ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment