I would like to click on a link on the website http://www.furaffinity.net/view/33063264/ but the <a>
element has no description factors so, I have no idea how to find it properly. This may be set as a duplicate of my other question but, this will be more descriptive and better organized.
JSFiddle: https://jsfiddle.net/60obtL8v/
I have tried using JQuery to locate the element with no luck. I don't know if my code was wrong or not. I've deleted the code and would've liked to find it again but, I couldn't.
My JS script:
// ==UserScript==
// @name Say "Very Nice!"
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Say "Very Nice" on a post by clicking the button.
// @author You
// @match https://www.furaffinity.net/view/*
// @match http://www.furaffinity.net/view/*
// @match www.furaffinity.net/view/*
// @grant none
// ==/UserScript==
function addButton(text, onclick, cssObj) {
cssObj = cssObj || {position: 'absolute', bottom: '15%', left:'4%', '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(){
'use strict'
window.addEventListener('load', () => {
addButton('Very Nice!', gfg_Run)
})
var el_down = document.getElementById("JSMessage");
var inputF = document.getElementById("JSMessage");
var yeet = document.getElementsByClassName('button');
var inputH = document.getElementsByTagName("a");
function gfg_Run() {
inputF.value = "Very Nice!";
el_down.innerHTML =
"Value = " + "'" + inputF.value + "'";
yeet[0].click();
inputH.click();
}
}())
My expected results are that I could click on the <a>
tag by clicking on a button elsewhere on the page. I have no idea how i would even locate the element, as it is under a <div>
and a <b>
element.
An example of what the HTML of the page looks like:
<div class="alt1 actions aligncenter" style="margin-top: 8px;">
This is what i would like to click right here. --->
<b><a href="/fav/33151503/?key=37dfe6a83f38f48790a6551921ddb13850e2c6a0">+Add to Favorites</a></b> |
<b><a href="//d.facdn.net/art/legacy2988/stories/1569252982/1569252982.legacy2988_i’m_not_sure_atm.txt">Download</a></b> |
<b><a href="/full/33151503/">Full View</a></b> | <b><a href="/newpm/legacy2988/">Send note</a></b>
<div>Submission © 2019 Legacy2988</div>
</div>
Hopefully, I structured this question correctly.
The code looks like pure JS but in jQuery you can use the attribute selector to select the href and perform the action:
jQuery('a[@href*=/fav/33151503/?key=37dfe6a83f38f48790a6551921ddb13850e2c6a0]');
OR
$('a[@href*=/fav/33151503/?key=37dfe6a83f38f48790a6551921ddb13850e2c6a0]');