Mozilla FireFox Code Copy Add On
From QB64 Wiki
Some members have complained about not being able to copy the WIKI code examples using the Mozilla Firefox browser. When code is copied from an example and saved in a text editor, the code is pasted as one continuous line of text with no line breaks.
After months of searching we have finally found a solution to the problem. We wish to thank members NG, CodeGuy and others who contributed their efforts in finding the solution to the copy problem.
The Grease Monkey Mozilla Firefox Script Add-on:
- 1) Download the "Grease Monkey" add-on available below. This requires installing the program and adding it to Firefox and is more invasive. However the add-on allows you to change the look and functionality of other web pages also. Read more at the site:
- For more information about using the Greasemonkey program go to their homepage: http://www.greasespot.net/
- 2) After the installation, a monkey face should appear in the lower right corner of the Firefox window. Right-click on it and a menu should appear. Choose New User Script and give the script a name, leave the namespace as it is and add a description if you wish, if the namespace is empty you can type anything you like in that box (it mustn't be empty).
- 3) In some older Fire Fox versions the Includes section may have two link lines. Enter: http://qb64.net/wiki/* and http://www.qb64.net/wiki/*. This limits the use of the add-on to just the QB64 WIKI! An editor (the same chosen during installation), will appear with some rows already filled in by the Grease Monkey setup wizard. Append the following code AFTER the existing code that Greasemonkey creates:
var allLinks; allLinks = document.evaluate('//p[substring(@style,1,12)="padding: 1em"]', // '//p[@style="padding: 1em; line-height:100%; margin-left:10px; white-space: pre; font-family: Courier; background-color: black; color: lightgrey;"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i < allLinks.snapshotLength; i++) { var thisLink = allLinks.snapshotItem(i); var createElt; if (thisLink.namespaceURI == null) createElt = function (eltName) { return document.createElement(eltName); } else createElt = function (eltName) { return document.createElementNS(thisLink.namespaceURI, eltName); } var codeBox = createElt('div'); codeBox.className = "CodeBox"; codeBox.style.padding = thisLink.style.padding; codeBox.style.margin = thisLink.style.margin; codeBox.style.borderBottom = thisLink.style.borderBottom; codeBox.style.marginLeft = thisLink.style.marginLeft; codeBox.style.fontFamily = thisLink.style.fontFamily; codeBox.style.fontSize = thisLink.style.fontSize; codeBox.style.backgroundColor = thisLink.style.backgroundColor; codeBox.style.lineHeight = thisLink.style.lineHeight; codeBox.style.color = thisLink.style.color; createCodeBoxContent(thisLink.firstChild, codeBox); thisLink.parentNode.insertBefore(codeBox, thisLink.nextSibling); thisLink.parentNode.removeChild(thisLink); } function createCodeBoxContent(srcElt, destParentElt) { while (srcElt != null) { if (srcElt.nodeType == document.TEXT_NODE) { var txt = srcElt.nodeValue; var textArray = new Array(); txt = txt.replace(/\t/g, ' '); txt = txt.replace(/ /g, String.fromCharCode(0xA0)); textArray = txt.split('\n'); for (var i = 0; i < textArray.length; i++) { destParentElt.appendChild(document.createTextNode(textArray[i])); if (i + 1 < textArray.length) { destParentElt.appendChild(createElt('br')); } } } else { destParentElt.appendChild(srcElt.cloneNode(false)); createCodeBoxContent(srcElt.firstChild, destParentElt.lastChild); } srcElt = srcElt.nextSibling; } }
- If the above code does not copy correctly, go to the bottom of page 6 of this topic in the QB64 Forum for the code:
- 4) Save the code written so far and make sure that the Enabled box is checked. Then try copying the TEST code in grey below.
var allLinks; allLinks = document.evaluate('//p[substring(@style,1,12)="padding: 1em"]', // '//p[@style="padding: 1em; line-height:100%; margin-left:10px; white-space: pre; font-family: Courier; background-color: black; color: lightgrey;"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (var i = 0; i < allLinks.snapshotLength; i++) { var thisLink = allLinks.snapshotItem(i); var createElt; if (thisLink.namespaceURI == null) createElt = function (eltName) { return document.createElement(eltName); } else createElt = function (eltName) { return document.createElementNS(thisLink.namespaceURI, eltName); } var codeBox = createElt('div'); codeBox.className = "CodeBox"; codeBox.style.padding = thisLink.style.padding; codeBox.style.margin = thisLink.style.margin; codeBox.style.borderBottom = thisLink.style.borderBottom; codeBox.style.marginLeft = thisLink.style.marginLeft; codeBox.style.fontFamily = thisLink.style.fontFamily; codeBox.style.fontSize = thisLink.style.fontSize; codeBox.style.backgroundColor = thisLink.style.backgroundColor; codeBox.style.lineHeight = thisLink.style.lineHeight; codeBox.style.color = thisLink.style.color; createCodeBoxContent(thisLink.firstChild, codeBox); thisLink.parentNode.insertBefore(codeBox, thisLink.nextSibling); thisLink.parentNode.removeChild(thisLink); } function createCodeBoxContent(srcElt, destParentElt) { while (srcElt != null) { if (srcElt.nodeType == document.TEXT_NODE) { var txt = srcElt.nodeValue; var textArray = new Array(); txt = txt.replace(/\t/g, ' '); txt = txt.replace(/ /g, String.fromCharCode(0xA0)); textArray = txt.split('\n'); for (var i = 0; i < textArray.length; i++) { destParentElt.appendChild(document.createTextNode(textArray[i])); if (i + 1 < textArray.length) { destParentElt.appendChild(createElt('br')); } } } else { destParentElt.appendChild(srcElt.cloneNode(false)); createCodeBoxContent(srcElt.firstChild, destParentElt.lastChild); } srcElt = srcElt.nextSibling; } }
Reference:
- NOTE: QB64, its owner and members are NOT resposible for any damages resulting from the use or misuse of the process mentioned. By downloading either software package the user agrees and assumes all risk!