Last active
May 23, 2018 08:46
-
-
Save deanet/6179e151cd482a2a091135cadf208032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Whatsapp | |
// @namespace graphen | |
// @version 2.0 | |
// @description Add button and hotkey to hide contact names and avatars on web.whatsapp.com | |
// @author Graphen | |
// @match https://web.whatsapp.com/ | |
// @icon https://i.imgur.com/LeZuNg7.png | |
// @grant none | |
// ==/UserScript== | |
/* jshint esversion: 6 */ | |
(function() { | |
'use strict'; | |
var hidden = false; | |
var defaultbkg = 'lightgrey'; | |
var prevName = ''; | |
document.addEventListener('DOMContentLoaded', function() { | |
var el = document.querySelector('#pane-side'); | |
if(el){ | |
el.addEventListener("click", function() { | |
document.querySelector('#main ._1wjpf').innerHTML = ''; | |
}); | |
} | |
}); | |
// document.querySelector('#pane-side').addEventListener("click", function() { | |
// document.querySelector('#main ._1wjpf').innerHTML = ''; | |
// }); | |
window.addEventListener('load', () => { | |
checkScreenLoaded(); | |
// document.getElementById("spam").addEventListener("click", spam); | |
// prevName = document.querySelector('#main ._1wjpf').innerHTML; | |
// document.querySelector('#main ._1wjpf').innerHTML = randomName(); | |
// document.querySelector('#pane-side').addEventListener("click", function(){ document.querySelector('#main header ._1wjpf').innerHTML = 'testaja'; }); | |
// document.querySelector('#main ._1wjpf').addEventListener("click", replaceBintoro()); | |
document.addEventListener("keydown", function(e) { | |
var keyCode = e.keyCode; | |
if(keyCode==118) { | |
toggleShowHide(); | |
} | |
}, false); | |
}); | |
function checkScreenLoaded() { | |
setTimeout(function(){ | |
if (document.getElementById('side')) { | |
addButton('Hide / F7', toggleShowHide);replaceBintoro(); | |
console.log("WA Privacy: Button added."); | |
} else if (document.getElementById('main')) { | |
console.log("main div got"); | |
} | |
else { | |
checkScreenLoaded(); | |
console.log("WA Privacy: Not loaded."); | |
} | |
}, 1000); | |
} | |
function addButton(text, onclick, cssObj) { | |
cssObj = cssObj || {position: 'absolute', display: 'none', top: '15px', left:'70px', 'z-index': 5000, 'font-weight':'bold', border:'black solid', 'border-radius':'10px', | |
padding:'4px', 'background-color': defaultbkg, 'min-width': '75px', 'box-shadow':'grey 3px 3px 0px 0px'}; | |
let button = document.createElement('button'), btnStyle = button.style; | |
try{ | |
document.getElementById('side').appendChild(button); | |
} | |
catch(err){ | |
console.log("addButton: " + err); | |
} | |
button.innerHTML = text; | |
button.onclick = onclick; | |
button.classList = ['show-hide-btn unpressed']; | |
button.onmouseover = function() { | |
button.style["background-color"] = 'salmon'; | |
}; | |
button.onmouseout = function() { | |
button.style["background-color"] = defaultbkg; | |
}; | |
Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key]); | |
return button; | |
} | |
function toggleShowHide() { | |
var btn = document.getElementsByClassName('show-hide-btn')[0]; | |
var panel = document.getElementById('pane-side'); | |
var groupicon = document.querySelector('#main .O90ur'); | |
var partnerimage = document.querySelector('#main .Qgzj8.gqwaM'); | |
if (hidden) { | |
console.log("WA Privacy: Toggled show."); | |
//panel.setAttribute('style', 'display:block'); | |
defaultbkg = 'lightgrey'; | |
btn.innerHTML = 'Hide / F7'; | |
btn.style.left = '70px'; | |
btn.style.top = '15px'; | |
btn.style["box-shadow"] = 'grey 3px 3px 0px 0px'; | |
try { // show | |
document.querySelector('#main ._1wjpf').innerHTML = prevName; | |
document.querySelector('#main ._1wjpf').title = prevName; | |
// not every user/group has set an image | |
if (partnerimage) { | |
partnerimage.setAttribute('style', 'opacity:1 !important;'); | |
} | |
// subheadline for group chats | |
if (groupicon) { | |
groupicon.setAttribute('style', 'display:block;'); | |
} | |
} catch(err) { | |
console.log("toggleShow: " + err); | |
} | |
prevName = ''; | |
} else { | |
console.log("WA Privacy: Toggled hide."); | |
// panel.setAttribute('style', 'display:none'); | |
defaultbkg = 'grey'; | |
btn.innerHTML = 'Show / F7'; | |
btn.style.left = '73px'; | |
btn.style.top = '18px'; | |
btn.style["box-shadow"] = ''; | |
try { // hide | |
replaceBintoro(); | |
prevName = document.querySelector('#main ._1wjpf').innerHTML; | |
document.querySelector('#main ._1wjpf').innerHTML = randomName(); | |
document.querySelector('#main ._1wjpf').removeAttribute('title'); | |
// not every user/group has set an image | |
if (partnerimage) { | |
partnerimage.setAttribute('style', 'opacity:0 !important;'); | |
} | |
// subheadline for group chats | |
if (groupicon) { | |
groupicon.setAttribute('style', 'display:none;'); | |
} | |
} catch(err) { | |
console.log("toggleHide: " + err); | |
} | |
} | |
document.getElementsByClassName('show-hide-btn')[0].style["background-color"] = defaultbkg; | |
hidden = !hidden; | |
} | |
function randomName() { | |
var names = ['Grace Kelly', 'Nicolas Cage', 'Albert Einstein', 'Angus Young', 'Katy Perry', 'Leonardo DiCaprio', 'Cleopatra', 'Anonymous Pasta Lovers', | |
'Karl Lagerfeld', 'Holy Father', 'Homer Simpson', 'Barney Stinson', 'Walter White', 'Queen Victoria', 'Sheldon Cooper', 'Mahatma Gandhi']; | |
return names[Math.floor(Math.random() * names.length)]; | |
} | |
function replaceBintoro() { | |
var arr_elms = []; | |
arr_elms = document.body.getElementsByTagName("*"); | |
var elms_len = arr_elms.length; | |
for (var i = 0; i < elms_len; i++) { | |
if(arr_elms[i].getAttribute("Title") == "Tim BintoroHost.co.id"){ | |
//alert(" : " + arr_elms[i].getAttribute("Title")); | |
try { | |
arr_elms[i].innerHTML="Eagle Team"; | |
} | |
//prevName="eagle team"; | |
catch(err){ | |
console.log("Replace log: " + err); | |
} | |
//document.querySelector('#main ._1wjpf').innerHTML="Eagle Team"; | |
// names = 'Eagle Team'; | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment