Skip to content

Instantly share code, notes, and snippets.

@idpaterson
Last active December 10, 2019 17:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idpaterson/cf744573cac0f8fd0680dc35ff7bdfae to your computer and use it in GitHub Desktop.
Save idpaterson/cf744573cac0f8fd0680dc35ff7bdfae to your computer and use it in GitHub Desktop.

Spare5 Available Task Notifications

This userscript periodically checks the Spare5 task list for new web tasks, updating the tab icon and title in response to available tasks. Pin the tab and easily see that tasks are available when the icon is green.

Spare5 tab indications

The Greasemonkey or Tampermonkey browser extensions are required to install this script and receive automatic updates, see below for instructions.

Installation

For use with a userscript browser extension like Greasemonkey (Firefox) or Tampermonkey (Chrome). With one of these browser extensions installed you can install the userscript by clicking below:

Usage

Open a tab to your Spare5 tasks list and sign in. The userscript will periodically refresh this page to update the tab with the current status of available tasks.

Configuration

At this time there is no customization available for the userscript. You may edit the settings at the top of the userscript, but your edits will not be preserved if the userscript is updated.

Updates

This userscript is configured to support automatic updates when changes are published. Your userscript manager may prompt you to install updates when available; refer to this gist for information about the changes in each version.

Scope

This script is only activated on the following pages of spare5.com:

  • http*://app.spare5.com/fives/tasks/beta
  • http*://app.spare5.com/fives/tasks

All script activity is performed locally in your web browser based on the data available on the Spare5 page that you are viewing; the userscript does not load or contact any external systems.

History

0.1.x - August 2016

Fixed occasional initialization errors plaguing the 0.0.x series that occasionally caused the green icon to show despite no matching tasks available and embraced jQuery throughout for consistency. Also ensures that the page keeps reloading after an error such as the 500 ISE that popped up recently is encountered.

0.0.x - June 2016

Early adaptations of the core functionality and testing. The userscript provides changes to the browser tab title and icon to show when tasks are available.

License

MIT License

Copyright (c) 2016 Ian Paterson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// ==UserScript==
// @name Spare5 Available Task Notifications
// @description Periodically refreshes Spare5 checking for new tasks for use in background or pinned tabs. Tab icon turns from gray to green when tasks are available.
// @version 0.1.2
// @author Ian Paterson
// @namespace http://idpaterson.github.io/
// @license MIT - https://tldrlegal.com/license/mit-license
// @match http*://app.spare5.com/fives/tasks/beta
// @match http*://app.spare5.com/fives/tasks
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @require https://gist.githubusercontent.com/kepkin/ff99090c410ab1b5c8fa/raw/a1e229b38cb6eb169556ae9b5e751e5c81d59929/waitForKeyElements.js
// @run-at document-start
// @updateURL https://gist.github.com/idpaterson/cf744573cac0f8fd0680dc35ff7bdfae/raw/spare5-available-tasks.meta.js
// @downloadURL https://gist.github.com/idpaterson/cf744573cac0f8fd0680dc35ff7bdfae/raw/spare5-available-tasks.user.js
// ==/UserScript==
// ==UserScript==
// @name Spare5 Available Task Notifications
// @description Periodically refreshes Spare5 checking for new tasks for use in background or pinned tabs. Tab icon turns from gray to green when tasks are available.
// @version 0.1.2
// @author Ian Paterson
// @namespace http://idpaterson.github.io/
// @license MIT - https://tldrlegal.com/license/mit-license
// @match http*://app.spare5.com/fives/tasks/beta
// @match http*://app.spare5.com/fives/tasks
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @require https://gist.githubusercontent.com/kepkin/ff99090c410ab1b5c8fa/raw/a1e229b38cb6eb169556ae9b5e751e5c81d59929/waitForKeyElements.js
// @run-at document-start
// @updateURL https://gist.github.com/idpaterson/cf744573cac0f8fd0680dc35ff7bdfae/raw/spare5-available-tasks.meta.js
// @downloadURL https://gist.github.com/idpaterson/cf744573cac0f8fd0680dc35ff7bdfae/raw/spare5-available-tasks.user.js
// ==/UserScript==
// Do not interfere with any libraries used by Spare5
jQuery.noConflict();
(function($) {
'use strict';
// These tasks will not contribute to the active task count
// Insert task names here separated by commas, for example: var tasksToIgnore = 'Image Tagging, Fashion';
var tasksToIgnore = 'Free Resource, Tutorial, Practice';
var secondsToReload = 15;
var faviconInactive = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJl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if the tasks do not load to handle error pages
var notLoadingTimeout = setTimeout(function() {
location.reload();
}, secondsToReload * 1000);
if (tasksToIgnore) {
selectorsToIgnore = tasksToIgnore.split(/\s*,\s*/).map(function(text) { return ':not(:contains(' + text + '))'; }).join('');
}
function setupFavicon() {
faviconEl = $('head link[rel="icon"][sizes="16x16"]');
faviconActive = faviconEl.attr('href');
// Remove all favicons so that the previous icon is used
$('head link[rel="icon"]').remove();
}
function checkActiveTasks() {
// Even though the task items are loaded there is
// occasionally an additional delay needed
setTimeout(function() {
clearTimeout(notLoadingTimeout);
var activeTaskCount = $('.task-item.active' + selectorsToIgnore).length;
var favicon = faviconInactive;
if (activeTaskCount > 0) {
document.title += ' (' + activeTaskCount + ' active)';
secondsToReload = secondsToReload * 2;
favicon = faviconActive;
}
// Update to the appropriate favicon
faviconEl.attr('href', favicon)
.appendTo('head');
setTimeout(function() {
location.reload();
}, secondsToReload * 1000);
}, 500);
}
waitForKeyElements('head link[rel="icon"][sizes="16x16"]', setupFavicon, true);
waitForKeyElements('.task-item', checkActiveTasks, true);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment