-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathurlbar-spacing.js
56 lines (53 loc) · 1.61 KB
/
urlbar-spacing.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
// UrlBar Spacing
// version 2022.4.0
// https://forum.vivaldi.net/post/400239
// Adds a flexible margin around the Addressfield, depending
// on width of the window. The window can be dragged by clicking
// the margins.
(function urlBarSpacing() {
const spacing = "92%"; // change percentage to control spacing inside wrapper
const css = `
.vm-us-wrapper {
flex: 1 0;
-webkit-app-region: drag;
}
.vm-us-spacer {
display: flex;
margin-left: auto;
margin-right: auto;
width: ${spacing};
}
`;
function space(url) {
const check = document.getElementById("vm-us-css");
if (!check) {
const style = document.createElement("style");
style.id = "vm-us-css";
style.innerHTML = css;
document.getElementsByTagName("head")[0].appendChild(style);
}
const wrapper = document.createElement("div");
wrapper.classList.add("vm-us-wrapper");
const spacer = document.createElement("div");
spacer.classList.add("vm-us-spacer");
url.parentNode.replaceChild(wrapper, url);
wrapper.appendChild(spacer);
spacer.appendChild(url);
}
let appendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function () {
if (arguments[0].tagName === "DIV") {
setTimeout(
function () {
if (arguments[0].classList.contains("UrlBar-AddressField")) {
const check = document.querySelector(".vm-us-spacer");
if (!check) {
space(arguments[0]);
}
}
}.bind(this, arguments[0])
);
}
return appendChild.apply(this, arguments);
};
})();