-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitlab_description_in_title.user.js
45 lines (39 loc) · 1.6 KB
/
gitlab_description_in_title.user.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
// ==UserScript==
// @name GitLab Description In Title
// @namespace https://github.com/StaticPH
// @match *://gitlab.com/*/*
// @match *://gitlab.org/*/*
// @match *://git.synz.io/*/*
// @match *://gitlab.*.org/*/*
// @match *://salsa.debian.org/*/*
// @version 1.1
// @createdAt 5/22/2021
// @author StaticPH
// @description Try to add the description to the page title on Gitlab repositories.
// @license MIT
// @updateURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/gitlab_description_in_title.user.js
// @downloadURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/gitlab_description_in_title.user.js
// @homepageURL https://github.com/StaticPH/UserScripts
// @supportURL https://github.com/StaticPH/UserScripts/issues
// @icon https://about.gitlab.com/images/press/logo/svg/gitlab-icon-rgb.svg
// @grant none
// @run-at document-idle
// ==/UserScript==
(function(){
'use strict';
const maxAttempts = 5;
let attempt = 1;
setTimeout(function wait(){
let title = document.title;
let description = document.querySelector('meta[name="description"]').content;
//I've found that Unicode character 0x00B7, "Middle Dot", has led some editors to erroneously interpret the text in encodings other than UTF-8, so let's replace it.
title = title.replace(/\u00b7/g, '|');
if (description){
title = `${title.trim()} — ${description.trim()}`;
}
else if (attempt <= maxAttempts){
setTimeout(wait, attempt * 500);
}
document.title = title;
});
})();