patternjavascriptMinor
Userscript hiding boxes on LinkedIn
Viewed 0 times
boxeslinkedinhidinguserscript
Problem
When looking at people you may know on LinkedIn (requires you to be logged in) there are sometimes some annoying boxes that are for people who are email contacts but not on LinkedIn. I don't want to see these. If I wanted to connect with them and invite them to LinkedIn, I would have. So I wrote a userscript! I wrote a few versions, because I wasn't sure about all of these things. I've never written a userscript before, so let me know if any of this is weird, or not idiomatic, or something
This version uses jQuery! That seems like overkill though...
This version uses jQuery in a Chrome compatible way:
```
// ==UserScript==
// @name Hide invites - Chrome compatible
// @namespace http://dannnno.github.io/
// @description Hides those "Invite to network boxes" on LinkedIn in a Chrome compatible way
// @include https://www.linkedin.com/people/pymk/hub/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @grant GM_log
// ==/UserScript==
var version = "2.1.4";
// Code adapted from http://stackoverflow.com/a/12751531/3076272
if (typeof jQuery !== "function") {
add_jQuery(version);
}
function add_jQuery (jqVersion) {
var jqVersion = jqVersion || version;
var targ = document.getElementsByTagName('head')[0] || document.body || document.documentElement;
var scriptNode = document.createElement('script');
scriptNode.src = 'http://ajax.googleapis.com/ajax/libs/jquery/' + jqVersion + '/jquery.min.js';
scriptNode.addEventListener("load", function () {
var scriptNode = document.createElement("script");
sc
This version uses jQuery! That seems like overkill though...
// ==UserScript==
// @name Hide invites
// @namespace http://dannnno.github.io/
// @description Hides those "Invite to network boxes" on LinkedIn
// @include https://www.linkedin.com/people/pymk/hub/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @grant GM_log
// ==/UserScript==
$(document).on('scroll', function (event) {
$('li.card.guest').hide();
});This version uses jQuery in a Chrome compatible way:
```
// ==UserScript==
// @name Hide invites - Chrome compatible
// @namespace http://dannnno.github.io/
// @description Hides those "Invite to network boxes" on LinkedIn in a Chrome compatible way
// @include https://www.linkedin.com/people/pymk/hub/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @grant GM_log
// ==/UserScript==
var version = "2.1.4";
// Code adapted from http://stackoverflow.com/a/12751531/3076272
if (typeof jQuery !== "function") {
add_jQuery(version);
}
function add_jQuery (jqVersion) {
var jqVersion = jqVersion || version;
var targ = document.getElementsByTagName('head')[0] || document.body || document.documentElement;
var scriptNode = document.createElement('script');
scriptNode.src = 'http://ajax.googleapis.com/ajax/libs/jquery/' + jqVersion + '/jquery.min.js';
scriptNode.addEventListener("load", function () {
var scriptNode = document.createElement("script");
sc
Solution
After I did a little playing around in a LinkedIn page's source code and I found out that LinkedIn already uses jQuery: that means you don't need to worry about checking if jQuery exists in the page because the page already has it.
Therefore, you can strip away all the jQuery injection nonsense, leaving your code looking like this;
If you would like a review on how you did the on the vanilla JavaScript, leave a comment.
Therefore, you can strip away all the jQuery injection nonsense, leaving your code looking like this;
var version = "2.1.4";
jQuery(document).on('scroll', function (event) {
jQuery('li.card.guest').hide();
});If you would like a review on how you did the on the vanilla JavaScript, leave a comment.
Code Snippets
var version = "2.1.4";
jQuery(document).on('scroll', function (event) {
jQuery('li.card.guest').hide();
});Context
StackExchange Code Review Q#101398, answer score: 2
Revisions (0)
No revisions yet.