Skip to content

Instantly share code, notes, and snippets.

@MattArnold
Last active February 5, 2018 19:26
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 MattArnold/4b038feb74efc8c16d527afddb37a738 to your computer and use it in GitHub Desktop.
Save MattArnold/4b038feb74efc8c16d527afddb37a738 to your computer and use it in GitHub Desktop.
Trim Leading And Trailing Whitespace From Paste
// ==UserScript==
// @name Trim leading and trailing whitespace from paste
// @namespace https://gist.githubusercontent.com/MattArnold
// @version 0.2
// @description Trim leading and trailing whitespace from paste
// @author Matt Arnold
// @updateURL https://gist.githubusercontent.com/MattArnold/4b038feb74efc8c16d527afddb37a738/raw/c58b50cf1e8872df1982c7475e2176635f5ba9f0
// @downloadURL https://gist.githubusercontent.com/MattArnold/4b038feb74efc8c16d527afddb37a738/raw/c58b50cf1e8872df1982c7475e2176635f5ba9f0
// @match https://moosejaw.info/MachII/POSv2/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
$(document).ready(function() {
var search = document.getElementById('ctl00_cphMainContent_txtQuickSearch');
var cleanPaste;
cleanPaste = function(e) {
e.preventDefault();
var pastedText = '';
if (window.clipboardData && window.clipboardData.getData) { // IE
pastedText = window.clipboardData.getData('Text');
} else if (e.clipboardData && e.clipboardData.getData) {
pastedText = e.clipboardData.getData('text/plain');
}
this.value = pastedText.replace(/^\s+|\s+$/g, '');
};
search.onpaste = cleanPaste;
console.log('Trim leading and trailing whitespace from paste');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment