Skip to content

Instantly share code, notes, and snippets.

@heddn
Forked from clemens-tolboom/tagAmsterdam2014.user.js
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heddn/4f40995746704071329c to your computer and use it in GitHub Desktop.
Save heddn/4f40995746704071329c to your computer and use it in GitHub Desktop.
// ==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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment