-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinkedin-new-options.user.js
More file actions
139 lines (109 loc) · 4.89 KB
/
linkedin-new-options.user.js
File metadata and controls
139 lines (109 loc) · 4.89 KB
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
// ==UserScript==
// @name Linkedin New Options
// @namespace http://stackoverflow.com/users/982924/rasg
// @author RASG
// @description Add new options to Linkedin
// @require http://code.jquery.com/jquery.min.js
// @require https://raw.github.com/odyniec/MonkeyConfig/master/monkeyconfig.js
// @require https://cdn.jsdelivr.net/npm/siiimple-toast/dist/siiimple-toast.min.js
// @resource toastcss https://cdn.jsdelivr.net/npm/siiimple-toast/dist/style.css
// @include http*://*linkedin.com/*
// @icon https://www.google.com/s2/favicons?domain=linkedin.com
// @version 2023.05.05.1002
// @grant GM_addStyle
// @grant GM_getMetadata
// @grant GM_getResourceText
// @grant GM_getValue
// @grant GM_notification
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
// -----------------------------------------------------------------------------
// LOAD TOAST NOTIFICATIONS LIBRARY
// -----------------------------------------------------------------------------
// @require https://cdn.jsdelivr.net/npm/siiimple-toast/dist/siiimple-toast.min.js
// @resource toastcss https://cdn.jsdelivr.net/npm/siiimple-toast/dist/style.css
// @grant GM_addStyle
// @grant GM_getResourceText
GM_addStyle( GM_getResourceText("toastcss") );
var toast = siiimpleToast.setOptions({
position: 'top|right',
duration: 3000,
});
// -----------------------------------------------------------------------------
// PREVENT JQUERY CONFLICT
// -----------------------------------------------------------------------------
var $ = window.$;
var jQuery = window.jQuery;
this.$ = this.jQuery = jQuery.noConflict(true);
if (typeof $ == 'undefined') console.log('JQuery not found; The script will certainly fail');
// -----------------------------------------------------------------------------
// OPTIONS / CONFIG MENU
// -----------------------------------------------------------------------------
var parametros = {
open_links_in_new_tab : { type: 'checkbox', default: true },
page_wide : { type: 'checkbox', default: true },
};
var cfg;
try {
cfg = new MonkeyConfig({
title: 'Config Linkedin New Options',
menuCommand: true,
onSave: function() { fnSaveChanges(); },
params: parametros
});
console.log("MonkeyConfig loaded; The settings menu will be enabled");
}
catch(err) {
console.log(err);
console.log("MonkeyConfig not loaded; The settings menu will be disabled");
cfg = {
params: parametros,
get: function get(name) { return GM_getValue(name, this.params[name].default) }
}
}
// -----------------------------------------------------------------------------
// START
// -----------------------------------------------------------------------------
var shouldreload = false;
// apply imediately at document start
fnCheckChanges();
// also wait for page load. jquery will be ready here
$(function() {
// monitor the page for changes and reapply if necessary
// use 'observer.disconnect()' in 'fnCheckChanges()' to stop monitoring
var alvo = document.querySelector('body');
var observer = new MutationObserver(fnCheckChanges);
observer.observe(alvo, { attributes: false, characterData: false, childList: true, subtree: true });
});
// -----------------------------------------------------------------------------
// FUNCTIONS
// -----------------------------------------------------------------------------
function fnCheckChanges(changes, observer) {
$('#ads-container, .org-container__ad-module, .ad-banner-container').remove();
var page_size = '';
if (cfg.get("page_wide")) page_size = 'unset';
$('div.scaffold-layout-container').width('100%').css('max-width', page_size);
$('div.job-view-layout > div.grid').width(page_size).css('max-width', page_size);
$('button[data-control-name*="see_more"], button[aria-label*="Click to see more"]').click();
if (cfg.get("open_links_in_new_tab")) fnReplaceLinks();
}
// -----------------------------------------------------------------------------
function fnReplaceLinks() {
[...document.links].forEach(
a => $(a).filter(function() {
return this.href.match(/^http/) && this.hostname !== location.hostname;
}).attr('target', '_blank')
);
}
// -----------------------------------------------------------------------------
function fnSaveChanges() {
$('body').on("click", "#reloadnow", function() {
$(this).fadeOut("fast", function() { document.location.reload(false); });
});
var msg_success = 'Settings saved';
toast.success(msg_success);
var msg_reload = '<span id="reloadnow"> Some changes will be applied after you reload the page. <br> Click here to reload now </span>';
if (shouldreload) toast.message(msg_reload, { delay: 3000, duration: 7000 });
}