-
Notifications
You must be signed in to change notification settings - Fork 20
/
move-window-buttons-maximized.js
178 lines (152 loc) · 6.35 KB
/
move-window-buttons-maximized.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//Move Minimize/Zoom/Close buttons to addressbar when Vivaldi is maximized and tab position is NOT "Top"
(function () {
vivaldi.jdhooks.addStyle(`
#browser:not(.popup):not(.horizontal-menu):not(.tabs-top).maximized #header,
#browser:not(.popup):not(.horizontal-menu):not(.tabs-top).native #header { display: none; }
#browser.horizontal-menu .MaximizedWindowButtons,
#browser.tabs-top .MaximizedWindowButtons,
#browser:not(.maximized) .MaximizedWindowButtons,
#browser.native .MaximizedWindowButtons { display: none }
.MaximizedWindowButtons.window-buttongroup {
position: relative !important;
align-self: baseline;
}
#vivaldi-button-moved {
order: -1;
display: none;
}
#browser:not(.horizontal-menu):not(.tabs-top).maximized #vivaldi-button-moved,
#browser:not(.horizontal-menu):not(.tabs-top).native #vivaldi-button-moved {
display: initial;
flex: 0;
padding-right: 34px;
}
.toolbar-mailbar {
--ToolbarItemGap: 4px;
}
/* copypasted from common.css, "#header #titlebar .window-buttongroup" replaced with ".MaximizedWindowButtons" */
#browser.win.win10 .MaximizedWindowButtons button.window-close {
background-color: transparent;
fill: var(--colorImageForeground, inherit);
}
#browser.win.win10 .MaximizedWindowButtons {
overflow: hidden;
line-height: initial;
}
#browser.win.win10 .MaximizedWindowButtons button.window-minimize svg {
margin: auto;
}
.tabs-right#browser.win.win10 .MaximizedWindowButtons button.window-close,
.tabs-left#browser.win.win10 .MaximizedWindowButtons button.window-close,
.tabs-bottom#browser.win.win10 .MaximizedWindowButtons button.window-close {
fill: var(--colorFg, var(--colorImageForeground));
}
.color-behind-tabs-off.tabs-right#browser.win.win10 .MaximizedWindowButtons button.window-close,
.color-behind-tabs-off.tabs-left#browser.win.win10 .MaximizedWindowButtons button.window-close,
.color-behind-tabs-off.tabs-bottom#browser.win.win10 .MaximizedWindowButtons button.window-close {
fill: var(--colorAccentFg, var(--colorImageForeground));
}
#browser.win.win10 .MaximizedWindowButtons button.window-close:hover {
fill: #fff;
background-color: #e3423e;
}
#browser.win.win10 .MaximizedWindowButtons button:hover {
fill: var(--colorImageForeground, inherit);
}
.tabs-right#browser.win.win10 .tabs-bottom#browser.win.win10 .tabs-left#browser.win.win10,
#browser.win.win10 .MaximizedWindowButtons.window-buttongroup button {
height: 25px;
}
`, "move-window-buttons-maximized.js")
function hookFunction(oldClass) {
const React = vivaldi.jdhooks.require("React")
const ShowMenu = vivaldi.jdhooks.require("_ShowMenu")
const CommandManager = vivaldi.jdhooks.require("_CommandManager")
const ToolbarButton = vivaldi.jdhooks.require("toolbars_ToolbarButton")
class newClass extends oldClass {
vivaldiButtonClick(event) {
const rect = event.target.getBoundingClientRect()
const props = {
id: 0,
rect: {
x: parseInt(rect.left),
y: parseInt(rect.top),
width: parseInt(rect.width),
height: parseInt(rect.height)
},
menu: {
items: CommandManager.getNamedMenu("vivaldi", true),
expandId: "",
preferred: []
}
}
ShowMenu.show(props.id, [props], "bottom")
}
render() {
let ret = super.render()
let iconClose, iconMinimize, iconZoom
const platform = window.navigator.platform.indexOf("Linux") >= 0 ?
"linux" :
navigator.platform.indexOf("MacIntel") >= 0 ?
"mac" :
window.navigator.appVersion.indexOf("Windows NT 10") >= 0 ?
"win10" :
"win"
switch (platform) {
case "linux":
case "win":
iconClose = vivaldi.jdhooks.require("_svg_window_close")
iconMinimize = vivaldi.jdhooks.require("_svg_window_minimize")
iconZoom = vivaldi.jdhooks.require("_svg_window_zoom")
break
case "win10":
iconClose = vivaldi.jdhooks.require("_svg_window_close_win10")
iconMinimize = vivaldi.jdhooks.require("_svg_window_minimize_win10")
iconZoom = vivaldi.jdhooks.require("_svg_window_zoom_win10")
break
case "mac":
iconClose = vivaldi.jdhooks.require("_svg_window_close_mac")
iconMinimize = vivaldi.jdhooks.require("_svg_window_minimize_mac")
iconZoom = vivaldi.jdhooks.require("_svg_window_zoom_mac")
}
function createButton(className, image) {
return React.createElement("button", {
tabIndex: "-1",
className: "MaximizedWindowButtons " + className,
style: {
order: 255
},
onClick: function () {
document.querySelector(`#browser > #header > #titlebar .${className}`).click()
},
dangerouslySetInnerHTML: {
__html: image
}
})
}
ret.props.children.push(
React.createElement("div", {
className: "toolbar toolbar-mainbar",
id: "vivaldi-button-moved"
},
React.createElement(ToolbarButton, {
tooltip: "Menu",
onClick: this.vivaldiButtonClick.bind(this),
image: vivaldi.jdhooks.require("_svg_menu_vivaldi")
})
))
ret.props.children.push(
React.createElement("div", { className: "MaximizedWindowButtons window-buttongroup" },
createButton("window-minimize", iconMinimize),
createButton("window-maximize", iconZoom),
createButton("window-close", iconClose)
)
)
return ret
}
}
return newClass
}
vivaldi.jdhooks.hookClass("urlfield_UrlBar", hookFunction)
vivaldi.jdhooks.hookClass("mail_MailBar", hookFunction)
})()