Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
User script: Add a select list to WordPress edit pages to make it easy to set a publication date in the past
{
"manifest_version": 2,
"content_scripts": [ {
"exclude_globs": [ ],
"include_globs": [ "BLOG_URL/wp-admin/post*" ],
"js": [ "script.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_idle"
} ],
"converted_from_user_script": true,
"description": "Add a select list to WordPress edit pages to make it easy to set a publication date in the past",
"key": "Ilesh6T+3DJiNzNbQXBGjKp0J9uU8sLBwA+kAMEzyRI=",
"name": "WordPress Quick Pick",
"version": "1.0"
}
// ==UserScript==
// @name WordPress Quick Pick
// @namespace http://thunderguy.com/
// @description Add a select list to WordPress edit pages to make it easy to set a publication date in the past
// @author Bennett McElwee, bennett@thunderguy.com
// ==/UserScript==
// Chrome-compatible script injection: http://stackoverflow.com/a/8890387/61754
var main = function () {
(function($) {
var dayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var monthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
$(".edit-timestamp").after("<div><select class='day-picker'><option>Quick pick...</option></select></div>");
var sysTime = new Date().getTime();
for (var i = 0; i < 15; ++i) {
var date = new Date(sysTime - i * 24 * 60 * 60 * 1000);
var day = date.getDate();
var month = date.getMonth() + 1; if (month < 10) { month = "0" + month; }
var year = date.getFullYear();
var text = dayNames[date.getDay()] + " " + day + " " + monthNames[date.getMonth()] + " " + year;
if (i == 0) { text = text + " - today"; }
else if (i == 1) { text = text + " - yesterday"; }
$(".day-picker").append("<option value='"+year+"-"+month+"-"+day+"'>"+text+"</option>")
}
$(".day-picker").change(function() {
var date = $(this).val().split("-");
$("#aa").val(date[0]);
$("#mm").val(date[1]);
$("#jj").val(date[2]);
$(this).val("");
$(".save-timestamp").click();
});
})(window.jQuery);
};
// Inject the main script
var script = document.createElement("script");
script.textContent = "(" + main.toString() + ")();";
document.body.appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment