avada wrote:
There's another weird thing I noticed recently. The select all feature in forums, such as with the code "sections" on this forums don't work. The page is just scrolled to the top.
Chrome Dev ver.58.0.3026.3 is also same behavior.
This behavior was introduced by the following bug:
[*]#1321623[Core:Selection]-Implement setBaseAndExtent[Uns][[platform-rel-Google][platform-rel-GoogleSuite][platform-rel-GoogleDocs] ]
And, I think Mozillazine needs to update phpBB code forum_fn.js.
function selectCode(a)
{
// Get ID of code block
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
// Not IE and IE9+
if (window.getSelection)
{
var s = window.getSelection();
// Safari
if (s.setBaseAndExtent)
{
s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
}
// Firefox and Opera
else
{
// workaround for bug # 42885
if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
{
e.innerHTML = e.innerHTML + ' ';
}
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Some older browsers
else if (document.getSelection)
{
var s = document.getSelection();
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
// IE
else if (document.selection)
{
var r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
function selectCode(a) {
'use strict';
// Get ID of code block
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
var s, r;
// Not IE and IE9+
if (window.getSelection) {
s = window.getSelection();
// Safari and Chrome
if (s.setBaseAndExtent) {
var l = (e.innerText.length > 1) ? e.innerText.length - 1 : 1;
try {
s.setBaseAndExtent(e, 0, e, l);
} catch (error) {
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Firefox and Opera
else {
// workaround for bug # 42885
if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') {
e.innerHTML = e.innerHTML + ' ';
}
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Some older browsers
else if (document.getSelection) {
s = document.getSelection();
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
// IE
else if (document.selection) {
r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
// ==UserScript==
// @name fix_SELECT_ALL_stops_working.user.js
// @description SELECT ALL stops working
// @include http://forums.mozillazine.org/viewtopic.php?*
// @grant none
// ==/UserScript==
var scriptCode = new Array(); // this is where we are going to build our new script
// here's the build of the new script, one line at a time
var func = function selectCode(a) {
'use strict';
// Get ID of code block
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
var s, r;
// Not IE and IE9+
if (window.getSelection) {
s = window.getSelection();
// Safari and Chrome
if (s.setBaseAndExtent) {
var l = (e.innerText.length > 1) ? e.innerText.length - 1 : 1;
try {
s.setBaseAndExtent(e, 0, e, l);
} catch (error) {
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Firefox and Opera
else {
// workaround for bug # 42885
if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') {
e.innerHTML = e.innerHTML + ' ';
}
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
// Some older browsers
else if (document.getSelection) {
s = document.getSelection();
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
// IE
else if (document.selection) {
r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
scriptCode.push(func.toString());
// now, we put the script in a new script element in the DOM
var script = document.createElement('script'); // create the script element
script.innerHTML = scriptCode.join('\n'); // add the script code to it
scriptCode.length = 0; // recover the memory we used to build the script
// this is sort of hard to read, because it's doing 2 things:
// 1. finds the first <head> tag on the page
// 2. adds the new script just before the </head> tag
document.getElementsByTagName('head')[0].appendChild(script);
mozillaZine is an independent Mozilla community and advocacy site. We're not affiliated or endorsed by the Mozilla Corporation but we love them just the same.