Mini SALR

Minimal Version of SALR

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

Advertisement:

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

Advertisement:

/*
	Mini SALR - Minimal Browser Plugin for surfing the Something Awful Forums
  Copyright (C) 2015 Ben Leffler

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// ==UserScript==
// @name        Mini SALR
// @namespace   https://gitlab.com/btleffler/mini-salr
// @description Minimal Version of SALR
// @author      Ben Leffler
// @copyright   2015+, btleffler (http://btleffler.github.io/)
// @license     GNU GPLv3
// @homepage    https://gitlab.com/btleffler/mini-salr
// @homepageURL https://gitlab.com/btleffler/mini-salr
// @supportURL  https://gitlab.com/btleffler/mini-salr/issues
// @match       https://forums.somethingawful.com/*
// @match       http://forums.somethingawful.com/*
// @require     https://code.jquery.com/jquery-2.1.4.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/tinycolor/1.3.0/tinycolor.min.js
// @version     1.1.2
// @grant       GM_openInTab
// @grant       window.open
// @grant       window.focus
// ==/UserScript==

(function ($, Color) {
	"use strict";

	var toOpen = [],
		container, link, Util;

	var DARKNESS = {
		"SEEN": 10,
		"UNSEEN": 0
	};

	function openTab (url) {
		if (window.GM_openInTab) {
			return GM_openInTab(url, false);
		}

		window.open(url, "_blank");
	}

	// I am an asshole, but...
	$("div.oma_pal, div#ad_banner_user").remove();

	container = $("#forum th.title");

	// Modify Thread Table Row Background Colors and Capture New Post Hrefs
	$("tr.thread.seen").each(function () {
		var $this = $(this),
			$newPostLink = $this.find("a.count"),
			darkness = DARKNESS.SEEN;

		if ($newPostLink.length) {
			darkness = DARKNESS.UNSEEN;
			toOpen.push($newPostLink.first().prop("href"));
		}

		$(this).children("td").each(function () {
			var $this = $(this),
				color = new Color($this.css("backgroundColor"));

			// Desaturate and modify the brightness of the background color
			$this.css(
				"backgroundColor",
				color.greyscale().darken(darkness).toString()
			);
		});
	});

	// If we aren't on the Control Panel,
	// or there aren't enough new posts, there's nothing else to do
	if (toOpen.length < 2 || !/usercp\.php$/.test(window.location.href)) {
		return;
	}

	link = $('<span>Open All Unread</span>').css({
		"font-weight": "bold",
		"display": "inline-block",
		"float": "right",
		"cursor": "pointer"
	});

	container.append(link);

	link.click(function (event) {
		var firstUrl;

		toOpen = toOpen.reverse();
		firstUrl = toOpen.pop();

		toOpen.forEach(openTab);

		window.focus();
		window.location.href = firstUrl;
	});
})(jQuery, tinycolor);