aboutsummaryrefslogtreecommitdiff
path: root/plugins/style/style.js
blob: c9e3f833dbcd5d0694d65ca708cc0e4828c7d641 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Replicates the Stylus app: <https://addons.mozilla.org/en-GB/firefox/addon/styl-us/>

var styles = null;

if (document.domain == "forum.effectivealtruism.org") {
  styles = `
	    .Layout-main {
                margin-left: 100px;
	    }
            .SingleColumnSection-root {
                width: 1000px !important;
                max-width: 1400px !important;
                padding-left: 100px !important;
            }
            .NavigationStandalone-sidebar {
                display: none;
            }
            .intercom-lightweight-app{
                display: none;
            }
  `;
  var styleSheet = document.createElement("style");
  styleSheet.innerText = styles;
  document.head.appendChild(styleSheet);
  console.log("Style changed");
}

if (document.domain == "mail.proton.me") {
  styles = `
	    /*
			.item-container-row.read, .item-container.read {
					background-color: white;
			}
			.item-container-row.unread, .item-container.unread {
					background-color: #E8E8E8;
			}
			.selection .item-container-row.item-is-selected, .item-container.item-is-selected {
					background-color: var(--selection-background-color) !important;
			}
     zoom: 0.625 !important;
			*/
	`;
}
if (document.domain == "forum.nunosempere.com") {
  styles = `
   body {
     zoom: 0.625 !important;
	 }
  `;
}
if (document.domain == "search.nunosempere.com") {
  styles = `
   body {
     /* zoom: 1.8; */
	 }

   footer {
     display: none;
	 }
  `;
}
if (document.domain == "twitter.com") {
  styles = `
	/* hide promoted tweets */
	:has(meta[property="og:site_name"][content="Twitter"])
		[data-testid="cellInnerDiv"]:has(svg + [dir="auto"]) {
		display: none;
	}
	[data-testid^="placementTracking"] {
		display: none;
	}

  /* hide what's happening section */
  :has(meta[property="og:site_name"][content="Twitter"])
    [aria-label="Timeline: Trending now"] {
    display: none !important;
  }
	[data-testid^="sidebarColumn"] {
		display: none;
	}

	/* Hide DMs v2 */
	[data-testid^="DMDrawerHeader"] {
		display: none;
	}

	/* Tweak main column */
	[data-testid^="primaryColumn"] {
		min-width: 900px;
		max-width: 900px;
	}
	[data-testid^="cellInnerDiv"] {
		min-width: 700px;
		max-width: 700px;
	}
	[aria-label^="Timeline: Conversation"]{
	  margin-left: 145px;
	}
	[data-testid^="DMDrawer"]{
	  display: none;
	}

	/* Delete a few unused or annoying elements */
	[aria-label^="Verified Orgs"] {
		display: none;
	}
	[aria-label^="Lists"] {
		display: none;
	}
	[aria-label^="Communities"] {
		display: none;
	}
	[aria-label^="Primary"] {
		margin-top: 50px;
	}
	[role^="progressbar"]{
		display: none;
	}

	/* hide video */
  [data-testid^="videoPlayer"] {
    display: none !important;
  }

  /* No change of colors in hover */
  *:hover {
    /* background-color: white !important; */
    background-color: !important;
    transition: none !important;
  }*/
  /*
  *:hover {
    background-color: inherit !important;
    transition: none !important;
  }*/
  /* Hide go to top button */
  [aria-label^="New posts are available. Push the period key to go to the them."]{
		display: none;
  }

  /* No transparency at the top */
  [aria-live^="polite"]{
    background: white !important;
  }

  `;

  // Function to hide the grandparent of video players
  function hideVideoPlayerGrandparent() {
    document
      .querySelectorAll('[data-testid="videoPlayer"]')
      .forEach(function (videoPlayer) {
        var grandparentElement = videoPlayer.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
        var newTextElement = document.createElement('div');
        newTextElement.textContent = ' [ twitter video ] ';
        newTextElement.style["margin-top"] = "10px";
        newTextElement.style["margin-left"] = "10px";
        newTextElement.style["margin-bottom"] = "10px";
        grandparentElement.replaceWith(newTextElement);
      });
  }

  // Create a new MutationObserver instance
  var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
      if (mutation.addedNodes.length) {
        hideVideoPlayerGrandparent(); // Call the function to hide video players
      }
    });
  });

  // Options for the observer (which mutations to observe)
  var config = { childList: true, subtree: true };

  // Start observing the target node for configured mutations
  observer.observe(document.body, config);

  // Call the function initially to hide any video players on initial load
  hideVideoPlayerGrandparent();
}

if (document.domain == "reddit.com" || document.domain == "old.reddit.com") {
  styles = `
	/* kill sidebar ads */
	.native-ad-container,
	.premium-banner-outer,
	.native-sidebar-ad,
	.infobar-toaster-container,
	#eu-cookie-policy,
	.ad-container,
	.listingsignupbar,
	a[href="/premium"],
	[data-promoted^="true"],
	a[href^="https://alb.reddit.com"]
	{
		display: none !important;
	}
	`;
}

if (styles != null) {
  var styleSheet = document.createElement("style");
  styleSheet.innerText = styles;
  document.head.appendChild(styleSheet);
  console.log("Style changed");
}

// Replace default alert with new function
// whose style can be changed!
window.alert = (message) => {
  let alertDiv = document.getElementById("customAlert");
  if (!alertDiv) {
    const html = `
            <div id="customAlert" class="custom-alert">
                <div class="custom-alert-content">
                    <p id="alertMessage"></p>
                    <button id="alertOkButton">OK</button>
                </div>
            </div>
            <style>
                .custom-alert {
                    display: none;
                    position: fixed;
                    z-index: 999;
                    left: 0;
                    top: 0;
                    width: 100%;
                    height: 100%;
                    overflow: auto;
                    background-color: rgba(0,0,0,0.4);
                }
                .custom-alert-content {
                    background-color: #fefefe;
                    margin: 15% auto;
                    padding: 20px;
                    border: 1px solid #888;
                    width: 80%;
                    font-family: monospace; /* Use monospace font */
                }
                .visible {
                    display: block;
                }
            </style>
        `;
    document.body.insertAdjacentHTML("beforeend", html);
    alertDiv = document.getElementById("customAlert");
    document.getElementById("alertOkButton").onclick = () => {
      alertDiv.classList.remove("visible");
      document.removeEventListener("keydown", dismissAlert);
    };
  }

  const dismissAlert = (event) => {
    if (
      event.key === "Enter" /*&& event.ctrlKey*/ &&
      alertDiv.classList.contains("visible")
    ) {
      alertDiv.classList.remove("visible");
      document.removeEventListener("keydown", dismissAlert);
    }
  };

  document.addEventListener("keydown", dismissAlert);
  document.getElementById("alertMessage").textContent = message;
  alertDiv.classList.add("visible");
};
// ^ takes 0.014ms to run, so performance is not the concern here.
// timed with console.time, console.timeEnd

document.body.style.visibility = "visible";