Create a gist now

Instantly share code, notes, and snippets.

This is a userscript that adds shortcuts for adding <kbd> tags to posts. Designed for Stack Exchange sites.
// ==UserScript==
// @name OBSOLETE: StackExchange, Add kbd shortcut
// @description Adds a button and a keyboard shortcut (Alt-K) to add <kbd> tags.
// @version 1.3
// @match *://*.askubuntu.com/*
// @match *://*.onstartups.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// ==/UserScript==
//-- On SE pages, use SE's error popup:
var targNode = $("#hmenus, .so-header").first ();
var seUtils = window.StackExchange;
console.warn ( `
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
This version of the "StackExchange, Add kbd shortcut" script is broken and obsolete.
Please uninstall it and (optionally) install the fixed and upgraded script.
The new script has been moved to GitHub proper. Find it at:
https://github.com/BrockA/SE-misc/blob/master/Add_kbd_sup_sub_shortcuts.user.js
For more information, see the post at Stack Apps:
http://stackapps.com/q/3341/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
` );
var alertMsg = `This version of the "Add kbd shortcut" script is obsolete. See the console for more info.`;
if (targNode.length && objHas (seUtils, "helpers.showErrorPopup") ) {
seUtils.helpers.showErrorPopup (targNode, alertMsg);
}
else
alert (alertMsg);
function objHas (obj, key) {
//-- Needed because .hasOwnProperty() does not work for nested properties. :(
return key.split (".").every (_rcrsvlyChkPropname);
//-- Declared function for better performance...
function _rcrsvlyChkPropname (propName) {
if ( obj === null || typeof obj !== "object" || ! (propName in obj) ) {
return false;
}
obj = obj[propName];
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment