Created
June 21, 2016 14:10
-
-
Save stylesuxx/eba0c6fe6b75742f203dda29d8922d95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ELR: Batch Management | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Manage a list of recipes to make in your next batch. | |
// @author [email protected] | |
// @match http://e-liquid-recipes.com/* | |
// @grant none | |
// ==/UserScript== | |
// @require http://code.jquery.com/jquery-latest.js | |
(function() { | |
'use strict'; | |
//localStorage.setItem("recipes", JSON.stringify([]));//JSON.stringify(recipes)); | |
var recipes = JSON.parse(localStorage.getItem("recipes")) || []; | |
var $currentBatch = $('<li />', {style: "margin-left: 5px"}) | |
.append($('<div />', {class: 'dropdown'}) | |
.append($('<a />', {class: 'mynavbtn dropdown-toggle', 'data-toggle':'dropdown', href: '#', text: 'Current Batch'}) | |
.append($('<i />', {style: 'margin-top: 8px', class: 'caret'}))) | |
.append($('<ul />', {class: 'dropdown-menu pull-right'}))); | |
$('ul.nav').first().append($currentBatch); | |
var appendLink = function(index, $link) { | |
var $remove = $('<div />', {style: 'margin-top: -23px; margin-right: 3px; font-weight: bold;', class: 'ric'}) | |
.append($('<i />', {class: "icon icon-trash"})); | |
$('.dropdown-menu', $currentBatch).append($('<li />', {item: index}).append($link).append($remove)); | |
$remove.on('click', function(e) { | |
e.preventDefault(); | |
var $parent = $(this).closest('li'); | |
removeLink($parent.attr('item')); | |
return false; | |
}); | |
}; | |
var removeLink = function(index) { | |
$('.dropdown-menu', $currentBatch).find('li[item=' + index + ']').remove(); | |
recipes.splice(index, 1); | |
localStorage.setItem("recipes", JSON.stringify(recipes)); | |
}; | |
$.each(recipes, function(index, item) { | |
appendLink(index, item); | |
}); | |
$('table.recipelist tr').each(function(index, item) { | |
var $add = $('<div />', {style: 'margin-top: -20px; margin-right: 20px; font-weight: bold;', class: 'ric', text: '+'}); | |
$('td', item).first().append($add); | |
$add.on('click', function(e) { | |
var count = recipes.length; | |
var $link = $(this).closest('td').find('a').clone(); | |
recipes.push($('<div>').append($link.clone()).html()); | |
localStorage.setItem("recipes", JSON.stringify(recipes)); | |
appendLink(count, $link); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment