-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathScratchPadMod.uc.js
94 lines (84 loc) · 3.63 KB
/
ScratchPadMod.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name ScratchPadMod.uc.js
// @description Let you choose which XULWindow to run your code in. Please set devtools.chrome.enabled to true before you can this script.
// @author NightsoN
// @namespace https://github.com/nightson
// @include chrome://devtools/content/scratchpad/scratchpad.xul
// @version 0.0.2 Updates the URL of scratchpad.xul(changeset 3b90d45a2bbc).
// @version 0.0.1
// ==/UserScript==
(function () {
var menu = $E([{
localName: 'menu',
attrs: {'id': 'sp-window-menu', 'label':'Window'},
nodes: [{
localName: 'menupopup',
attrs: {'id': 'sp-window-menupopup', 'datasources': 'rdf:window-mediator', 'ref': 'NC:WindowMediatorRoot'},
nodes: [{
localName: 'template',
nodes: [{
localName: 'rule',
nodes: [{
localName: 'menuitem',
attrs:{'uri': 'rdf:*', 'label': 'rdf:http://home.netscape.com/NC-rdf#Name', 'type': 'radio', 'oncommand': 'Scratchpad.setBrowserContext();'}
}]
}]
}]
}]
}]);
var menubar = document.getElementById('sp-menubar');
menubar.insertBefore(menu, document.getElementById('sp-help-menu'));
if (document.getElementById('sp-menu-content')) document.getElementById('sp-menu-content').setAttribute('onclick', 'Scratchpad.uncheckWindowMenu();');
Scratchpad.uncheckWindowMenu = function () {
if (document.querySelector('#sp-window-menupopup menuitem[checked="true"]')) {
document.querySelector('#sp-window-menupopup menuitem[checked="true"]').removeAttribute('checked');
}
}
Scratchpad.getSelectedWin = function () {
//Window mediator component https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Tutorial/XPCOM_Examples#Window_mediator_component
var wm = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"].getService();
wm.QueryInterface(Components.interfaces.nsIWindowDataSource);
var resource = document.querySelector('#sp-window-menupopup menuitem[checked="true"]').getAttribute('id')
return wm.getWindowForResource(resource);
}
Object.defineProperty(Scratchpad, "browserWindow", {
get: function(){
if (document.querySelector('#sp-window-menupopup menuitem[checked="true"]')) {
alert('1');
return this.getSelectedWin();
} else {
return Services.wm.getMostRecentWindow("navigator:browser");
}
}
})
Object.defineProperty(ScratchpadWindow, "browserWindow", {
get: function(){
if (document.querySelector('#sp-window-menupopup menuitem[checked="true"]')) {
alert('1');
return this.getSelectedWin();
} else {
return Services.wm.getMostRecentWindow("navigator:browser");
}
}
})
function $E(data, parent) {
parent = parent ? parent : document.createDocumentFragment();
var i,
p,
len = data.length;
for (i = 0; i < len; i++) {
let item = data[i];
let node = document.createElement(item.localName);
if (item.attrs) {
for (p in item.attrs) {
node.setAttribute(p, item.attrs[p]);
}
}
if (item.nodes) {
$E(item.nodes, node);
}
parent.appendChild(node);
}
return parent;
}
}());