//////////////////////////////////////////////////////////////////////////// // ==UserScript=== // @name Userscripts.org Source Numbering // @author Jerone UserScript Productions // @namespace http://userscripts.org/users/31497 // @homepage http://userscripts.org/scripts/show/38912 // @description Add line numbering to source code. // @description Userscripts.org Source Numbering v3 // @copyright 2008 - 2013 Jerone // @version v3 // @include *userscripts.org/scripts/review/* // ==/UserScript== /*////////////////////////////////////////////////////////////////////////// THIS SCRIPT IS PROVIDED BY THE AUTHOR `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SCRIPT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /*////////////////////////////////////////////////////////////////////////// //*** USER SETTINGS ***// var maxLines = 10000; // [Integer] maximum number of lines (prevent browser from hanging and possibly crashing); //*** USERSCRIPT ***// (function(win, doc, und) { try { var getStyle = function(node, attr){ if(doc.defaultView && doc.defaultView.getComputedStyle){ return doc.defaultView.getComputedStyle(node, null).getPropertyValue(attr); } else if(node.currentStyle){ return node.currentStyle[attr]; } return node.style[attr]; }; var USN = { Init: function(){ var pre; if((pre = doc.getElementById("source"))){ var preHeight = parseFloat(getStyle(pre, "height")), lineHeight = parseFloat(getStyle(pre, "line-height")) || 16.1; // px; // All the CSS; var css = " \ .numb { \ background-image: linear-gradient(0deg, #eee " + lineHeight + "px, transparent 0px) !important;\ background-size: 100% " + (lineHeight * 2) + "px !important; \ background-position: 0 4px !important; \ border: 1px solid #DDDDDD; \ float: left; \ margin: 0; \ padding: 5px 0; \ position: relative; \ width: 60px; \ z-index: 10; \ } \ .numbNr { \ font-family: monospace !important; \ font-size: 1.1em !important; \ } \ .numbNr td { \ border: 0px none !important; \ padding: 0px !important; \ text-align: center !important; \ } \ .numbNr a, \ .numbNr a:hover, \ .numbNr a:active { \ color: #333333; \ text-decoration:none; \ } \ .numbNr tr:hover a { \ font-size: 2em; \ line-height: 0.75em; \ } \ .numbNr a.decade { \ font-size: 2em; \ line-height: 0.75em; \ } \ .notice { \ margin-bottom: 16px !important; \ } \ .highlight { \ background-color:yellow !important; \ font: 1em/1.5 'andale mono','lucida console',monospace; \ font-size: 1.1em; \ height: 1.1em; \ left: 0; \ opacity: 0.5; \ position: absolute; \ width: 100%; \ z-index: 9; \ } \ #source { \ background-image: linear-gradient(0deg, #eee " + lineHeight + "px, transparent 0px) !important;\ background-size: 100% " + (lineHeight * 2) + "px !important; \ background-position: 0 4px !important; \ margin-top: 0px !important; \ margin-left: 60px !important; \ position: relative !important; \ z-index: 10; \ } \ /* Fix for buttons from 'uso - Count Issues' (http://userscripts.org/users/37004) */ \ .toolbar_menu { \ position: absolute; \ top: 2px; \ right: -4px; \ } \ "; var styler = doc.createElement("style"); styler.setAttribute("type", "text/css"); styler.appendChild(doc.createTextNode(css)); doc.getElementsByTagName("head")[0].appendChild(styler); var wrapper = doc.createElement("div"); wrapper.appendChild(pre.cloneNode(true)); pre.parentNode.replaceChild(wrapper, pre); pre = wrapper.firstChild; var div = doc.createElement("div"); div.className = "numb"; div.style.height = preHeight + "px"; pre.parentNode.insertBefore(div, pre); var table = doc.createElement("table"); table.width = "100%"; table.border = 0; table.cellspacing = 0; table.cellpadding = 0; table.className = "numbNr"; div.appendChild(table); var lines = (maxLines || 5000) + 1, i = 1; if(preHeight < ((lines + 10) * lineHeight)){ lines = pre.innerHTML.split(/\n/).length + 1; } for(; i