RSS Extractor

Collects RSS Feed Links

Click here to install Browse More Scripts
// ==UserScript==
// @name         RSS Extractor
// @namespace    c2cc48ec13a69a1386fd714c34bd0828d93c50e4
// @version      0.4
// @description  Collects RSS Feed Links
// @author       /u/AyrA_ch
// @match        http://*/*
// @match        https://*/*
// @grant        none
// ==/UserScript==

// Version History
// 0.4 Make this top most by default
// 0.3 Report reactivation method in console and allow for reactivation without a page reload
// 0.2 Allow to permanently hide the box
// 0.1 Initial Version

(function () {
	'use strict';
	//HTML encodes text
	var he = function (x) {
		var e = document.createElement("div");
		e.appendChild(document.createTextNode(x));
		return e.innerHTML;
	};

	//Searches for RSS feeds on the current page
	var scanRSS = function () {
		//Content Type filter for rss feeds
		var filter = /^application\/(atom|rss)\+xml$/i;
		//Elements that possibly can contain RSS information
		var all = Array.prototype.slice.call(document.querySelectorAll('link[rel=alternate]'));
		//Filter for RSS tags and extract usable values
		all = all.filter(function (v) {
				return v.href && filter.exec(v.type);
			}).map(function (v) {
				return {
					title: v.title || document.title,
					url: v.href,
					type: filter.exec(v.type)[1].toLowerCase()
				};
			});
		//Stop here if no RSS found
		if (all.length > 0) {
			//Create DIV element with all found RSS elements as a list
			var x = document.createElement('div');
			x.innerHTML = '<span title="Hold down SHIFT to disable this menu on this domain" style="cursor:pointer;color:#F00">[X]</span> RSS Feeds:<br /><ul style="list-style-type:none;padding:0;margin:0"><li>' +
				all.map(function (v) {
					return '<b>' + he(v.title) + '</b> <a target="_blank" href="' + he(v.url) + '">' + v.type + '</a>';
				}).join('</li><li>') + "</li></ul>";
			//Format DIV to look properly on most pages
			x.setAttribute('style', [
					'z-index:' + Number.MAX_SAFE_INTEGER,
					'border:2px solid #000',
					'font-size:10pt',
					'color:#000',
					'background-color:#FFF',
					'position:absolute',
					'top:5px',
					'right:5px',
					'display:inline-block',
					'padding:10px'].join(';'));
			document.body.appendChild(x);
			//Close handler with optional remembering
			x.querySelector('span').addEventListener('click', function (e) {
				if (e.shift || e.shiftKey) {
					localStorage['RSS-extract.disable'] = 'yes';
					alert('To enable this menu again, clear the site data (localStorage) in your browser.');
				}
				x.remove();
			});
		}
	};

	//Only scan for RSS feeds if not disabled on this website
	if (localStorage.getItem('RSS-extract.disable') !== 'yes') {
		scanRSS();
	} else {
		//Tell user how to enable this again
		console.log('RSS Extractor is disabled on this site. Clear all site data or type "enableRSS()" into the console to reactivate');
		window.enableRSS = function () {
			delete localStorage['RSS-extract.disable'];
			window.enableRSS = function () {};
			scanRSS();
		};
	}
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 18.118.19.123