Skip to content

Instantly share code, notes, and snippets.

@xiaoxiaoflood
Created June 30, 2019 18:59
Show Gist options
  • Save xiaoxiaoflood/75d3c6b37fbb7acbf45fca453e7b8b8e to your computer and use it in GitHub Desktop.
Save xiaoxiaoflood/75d3c6b37fbb7acbf45fca453e7b8b8e to your computer and use it in GitHub Desktop.
demo. very incomplete.
// ==UserScript==
// @name highlightScrollbar.uc.js
// @include main
// ==/UserScript==
(function() {
messageManager.loadFrameScript('data:application/javascript;charset=UTF-8,' +
encodeURIComponent('('+(function(){
var dis = this;
ChromeUtils.import("resource://gre/modules/Finder.jsm", this);
ChromeUtils.import("resource://gre/modules/FindContent.jsm", this);
this.fbtMandaAltura = function () {
var list = [];
var size = content.document.documentElement.getBoundingClientRect().height;
var spacobar = content.document.documentElement.clientHeight - 34;
hi._collectRectData().forEach(res => {
list.push((res.rectsAndTexts.rectList[0].top / size) * spacobar + 17 + 'px');
})
sendAsyncMessage('fbt', list);
}
this.Finder.prototype.onFindbarClose = function onFindbarClose() {
this.enableSelection();
this.highlighter.highlight(false);
sendAsyncMessage('fbtEsconde');
this.iterator.reset();
BrowserUtils.trackToolbarVisibility(this._docShell, "findbar", false);
}
this.Finder.prototype._notifyMatchesCount = function _notifyMatchesCount(result = this._currentMatchesCountResult) {
// The `_currentFound` property is only used for internal bookkeeping.
delete result._currentFound;
result.limit = this.matchesCountLimit;
if (result.total == result.limit)
result.total = -1;
for (let l of this._listeners) {
try {
l.onMatchesCountResult(result);
} catch (ex) {}
}
if (result.total && result.total < 101) {
dis.hi = (new dis.FindContent(docShell));
fbtMandaAltura();
} else {
sendAsyncMessage('fbtEsconde');
}
this._currentMatchesCountResult = null;
}
this.fbtTimeout = false;
this.fbtResizou = function() {
dis.hi = (new dis.FindContent(docShell));
if (dis.hi._collectRectData().length) {
fbtMandaAltura();
}
}
addEventListener('DOMWindowCreated', function () {
content.addEventListener('resize', function() {
clearTimeout(fbtTimeout);
fbtTimeout = setTimeout(fbtResizou, 100);
});
}, false);
}).toString() + ')();'), true);
messageManager.addMessageListener('fbt', function (message) {
if (!gBrowser.selectedBrowser.fbt) {
var gB = document.createElement('hbox');
gB.id = 'gridbox';
gB.style.direction = 'rtl';
gB.style.pointerEvents = 'none';
var fG = document.createElement('vbox');
var hl = document.createElement('vbox');
hl.id = 'fbtV';
hl.flex = '1';
hl.style.position = 'relative';
hl.style.padding = '17px 1px 17px 0px';
fG.appendChild(hl);
gBrowser.selectedBrowser.fbt = hl;
gB.appendChild(fG);
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"];
var estilo = '#fbtV > vbox { height: 2px; width: 15px; background-color: #38d878; z-index: 100; position: absolute; left: -15px; right: 1px; }';
sss.getService(Ci.nsIStyleSheetService).loadAndRegisterSheet(Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(estilo), null, null), sss.AGENT_SHEET);
for(let i = 0; i < 100; i++) {
gBrowser.selectedBrowser.fbt.appendChild(document.createElement('vbox'));
}
gBrowser.selectedBrowser.parentNode.appendChild(gB);
}
for (let i = 0; i < 100; i++) {
if (i < message.data.length) {
gBrowser.selectedBrowser.fbt.childNodes[i].style.top = message.data[i];
gBrowser.selectedBrowser.fbt.childNodes[i].style.display = 'block';
} else {
gBrowser.selectedBrowser.fbt.childNodes[i].style.display = 'none';
}
}
});
messageManager.addMessageListener('fbtEsconde', function () {
gBrowser.selectedBrowser.fbt && gBrowser.selectedBrowser.fbt.childNodes.forEach(el => el.style.display = 'none');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment