|
// ==UserScript== |
|
// @name SprintWeekend2015 |
|
// @namespace tagSprintWeekend2015 |
|
// @match https://www.drupal.org/node/* |
|
// @run-at document-end |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
// SAVE as tagSprintWeekend2015.user.js |
|
// Inspired by https://github.com/webflo/drupalsprint-bookmarklet/blob/gh-pages/index.html |
|
// Modified from https://gist.github.com/clemens-tolboom/7e15dac5bfb07a729f6e. |
|
// with the help of @helmo |
|
function addJQuery(callback) { |
|
var script = document.createElement("script"); |
|
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"); |
|
script.addEventListener('load', function() { |
|
var script = document.createElement("script"); |
|
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; |
|
document.body.appendChild(script); |
|
}, false); |
|
document.body.appendChild(script); |
|
} |
|
|
|
// the guts of this userscript |
|
function main() { |
|
var startdate = new Date('01/16/2015'); |
|
var enddate = new Date('01/19/2015'); |
|
var currentDate = new Date(); |
|
if (currentDate >= startdate && currentDate <= enddate) { |
|
// Uncomment if you want to limit the user script to a certain project on d.o. |
|
// if (jQuery('.field-name-field-project').find('.field-item').text() == 'Drupal core') { |
|
var tags = jQ('#edit-taxonomy-vocabulary-9-und').val(); |
|
var add_comma = tags.length > 0; |
|
tags = jQ.map(tags.split(', '), jQuery.trim); |
|
|
|
if (jQ.inArray('SprintWeekend2015', tags) === -1) { |
|
if (add_comma) { |
|
jQ('#edit-taxonomy-vocabulary-9-und').val(jQ('#edit-taxonomy-vocabulary-9-und').val() + ', SprintWeekend2015'); |
|
} else { |
|
jQ('#edit-taxonomy-vocabulary-9-und').val( 'SprintWeekend2015'); |
|
} |
|
} |
|
// } // IF END |
|
} |
|
} |
|
|
|
// load jQuery and execute the main function |
|
addJQuery(main); |