Reddit Unread Link

Changes the message icon so it always links to unread messages

Click here to install Browse More Scripts
// ==UserScript==
// @name         Reddit Unread Link
// @namespace    7bc2fd41da0b022eda93c0b84dd9a30985913b3a
// @version      0.5
// @description  Changes the message icon so it always links to unread messages
// @author       /u/AyrA_ch
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==

(function () {
	"use strict";
	var link = "/message/unread/";
	var setLink = function () {
		if (!setLink.schedule) {
			setLink.schedule = true;
			setTimeout(setLink, 200);
		} else {
			var items = ["#mail", "#NREMail"].map(function (v) {
				return document.querySelector(v);
			});
			setLink.schedule = false;
			for (var i = 0; i < items.length; i++) {
				var msg = items[i];
				if (msg && msg.getAttribute("href") != link) {
					msg.href = link;
					console.log("Message Link fixed");
				}
			}
		}
	};
	setLink.schedule = false;

	var mail = document.querySelector("#mail");
	if (mail) {
		var mo = new MutationObserver(setLink);
		mo.observe(mail, {
			attributes: true
		});
	}
	setLink();
})();

/*
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 3.137.175.80