I wanted to add a button to a page which upon clicked should open a link on new tab of the same browser window. I have tried one of the codes that was available on Stack Overflow however that did not serve my purpose. I was able to position the button on the page and rename that as per my need. However Only open thing that I am looking forward to is upon clicking that button I would need a new tab to be opened with the link that I specify. Kindly share your inputs.
Code is the second one on this link: Add a JavaScript button using Greasemonkey or Tampermonkey?
(function(){
'use strict'
window.addEventListener('load', () => {
addButton('Create Case', selectReadFn)
})
function addButton(text, onclick, cssObj) {
cssObj = cssObj || {position: 'absolute', bottom: '4.2%', left:'24.3%', 'z-index': 3}
let button = document.createElement('button'), btnStyle = button.style
document.body.appendChild(button)
button.innerHTML = text
button.onclick = onclick
Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
return button
}
function selectReadFn() {
[...document.getElementsByClassName('MN')].filter(isRead).forEach(element => element.click())
}
function isRead(element) {
childs = element.parentElement.parentElement.parentElement.getElementsByClassName('G3')
return ![...childs].some(e => e.innerText.search(/unread/i)!==-1)
}
}())