I would like to make a simple "Tweet" link with Tampermonkey for the Facebook posts. When you pressed the link, this needs to happened:
- A new tab opened which redirect you to the post page (for example:https://twitter.com/intent/tweet?text=https://facebook.com/troll0foci/photos/a.398396820226934.89024.398390086894274/1032904193442857/?type=3)
- The post content needs to be filled with the facebook post link and the post content.
My script can select the post links, but the posts content just simple no, because if I select the.userContentclass, I get all userContent element, which is not good, because I would like to get that content which belong the every induvidual post. However, every userContent element get a random generated class, like:_5pbx userContent
I would like to select this element with this random generated class. How can I do this?
My code is:
// ==UserScript==
// @name Twitter share
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author You
// @match https://www.facebook.com/
// @grant none
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
function finalcheck(){
if ($('.twitter-share-button').length == 0) {
var basehref="https://twitter.com/intent/tweet?text=https://facebook.com"+$("._5pcq").attr("href")+$(".usercontent p").text();
$(".comment_link").after('<a target="_blank" href="" class="twitter-share-button">Tweet</a>');
$(".twitter-share-button").attr("href",basehref);
}
if ($('.twitter-share-button').length >= 2) {
$('.twitter-share-button').not(':first').remove();
}
}
$( document ).on("hover",function() {
finalcheck();
});
$( document ).ready(function() {
setTimeout(function(){
finalcheck();
}, 1000);
});