// ==UserScript== // @name Github Notifications Dropdown // @namespace joeytwiddle // @copyright 2014-2017, Paul "Joey" Clark (http://neuralyte.org/~joey) // @version 1.1.3 // @license MIT // @description When clicking the notifications icon, displays notifications in a dropdown pane, without leaving the current page. // @include https://github.com/* // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @grant GM_addStyle // @downloadURL none // ==/UserScript== // bug: If the notifications list is longer than the page, scroll down to the bottom and then try to click on the white space below the Github document's content. The event does not fire there! // When using @grant none then we should also avoid messing with the page's jQuery (or lack of jQuery). this.$ = this.jQuery = jQuery.noConflict(true); // Contributors: joeytwiddle, SkyzohKeyx, Marti, darkred // ==Options== var makeBlocksCollapsableOnNotificationsPage = true; // Disabled by default because it was conflicting with other scripts (https://github.com/joeytwiddle/code/issues/2) var makeAllFileAndDiffBlocksCollapsable = false; // Github's blue dot (2017) //var notificationDotStyle = 'linear-gradient(hsl(212, 100%, 66%), hsl(212, 100%, 46%))'; // Github's blue dot (2016) //var notificationDotStyle = 'linear-gradient(hsl(214, 50%, 65%), hsl(214, 50%, 50%))'; // Strong red dot //var notificationDotStyle = 'linear-gradient(hsla(0, 80%, 75%, 1), hsla(0, 80%, 50%, 1))'; // Calm amber dot //var notificationDotStyle = 'linear-gradient(hsla(35, 90%, 65%, 1), hsla(35, 90%, 40%, 1))'; // Gentle green dot //var notificationDotStyle = 'linear-gradient(hsla(120, 50%, 65%, 1), hsla(120, 50%, 40%, 1))'; // ==/Options== var mainNotificationsPath = "/notifications"; var notificationButtonLink = $("header a.notification-indicator[href]"); var notificationButtonContainer = notificationButtonLink.closest(".Header-item"); var closeClickTargets = $("body, header a.notification-indicator[href]"); var notificationsDropdown = null; var tabArrow = null; function listenForNotificationClick(){ notificationButtonContainer.on("click", onNotificationButtonClicked); } function onNotificationButtonClicked(evt){ // Act normally (do nothing) if a modifier key is pressed, or if it was a right or middle click. if (evt.ctrlKey || evt.shiftKey || evt.metaKey || evt.which !== 1) { return; } evt.preventDefault(); notificationButtonContainer.off("click", onNotificationButtonClicked); // For GM 4.0 we must use an absolute path, so we use .prop() instead of .attr(). "This is an issue with Firefox and content scripts" var targetPage = notificationButtonLink.prop("href"); fetchNotifications(targetPage); } function fetchNotifications(targetPage){ notificationButtonContainer.css({ "opacity": "0.3", "outline": "none" }); $.ajax({ url: targetPage, dataType: "html" }).then(receiveNotificationsPage.bind(null,targetPage)).fail(receiveNotificationsPage); } function receiveNotificationsPage(targetPage, data, textStatus, jqXHR){ notificationButtonContainer.css("opacity", ""); notificationsDropdown = $("