Last active
February 5, 2018 19:26
-
-
Save MattArnold/4b038feb74efc8c16d527afddb37a738 to your computer and use it in GitHub Desktop.
Trim Leading And Trailing Whitespace From Paste
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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