-1

I have developed a Greasemonkey script to run on my favorite listing site. It generates a button at the top of the page :) then once clicked I can call in the function I want.

The problem is, the script I wanna call is in jquery format, and I learned that though jquery and javascript are close to each other, it is not possible to call jquery via javascript, plus the idea that I can't use the jquery since it give numerous conflict to the site :(

Here is the greasemonkey script:

// ==UserScript==
// @name         My Fancy New Userscript
// @namespace    http://your.homepage/
// @version      0.1
// @description  enter something useful
// @author       You
// @grant        none
// @include *
// ==/UserScript==

var input=document.createElement("input");
input.type="button";
input.value="GreaseMonkey Button";
input.onclick = showAlert;

document.body.insertBefore(input,document.body.firstChild); 

function showAlert()
{
    alert("Hello World");
}

And this is the jquery I want to run after clicking the button:

$("tr.project-description").filter(function() {
return !$("span.verfied-badge", this).length;
}).remove();

What it does is it removes the <tr> elements without the wanted <span class="verfied-badge"> the question is related here: javascript on page load check if a span (under <tr>) with a specific class exist, if does not exist remove the entire <tr>

Hope somebody can help. Thanks!

Community
  • 1
  • 1
The Wolf
  • 195
  • 3
  • 16
  • 3
    possible duplicate of [How can I use jQuery in Greasemonkey?](http://stackoverflow.com/questions/859024/how-can-i-use-jquery-in-greasemonkey) – Juicy Scripter Feb 24 '15 at 00:29
  • *The problem is, the script I wanna call is in jquery format, and I learned that though jquery and javascript are close to each other, it is not possible to call jquery via javascript* My heart just died a little after reading this. – Derek 朕會功夫 Feb 24 '15 at 00:44
  • I need to use javascript because jquery is in conflict :( – The Wolf Feb 24 '15 at 02:18

1 Answers1

0

Possible function:

(function(){
    var rows=document.querySelectorAll('tr.projection-description'),row;
    for(var r=rows.length-1;r>=0;r--){
      row=rows.item(r);
      if(!row.querySelector('span.verfied-badge')){
         row.parentNode.removeChild(row);
      }
    }
  }());
<table>
<tr class="projection-description"><td><span class="verfied-badge">verified-badge</span></td></tr>
<tr class="projection-description"><td><span>another badge</span></td></tr>
<tr class="projection-description"><td><span class="verfied-badge">verified-badge</span></td></tr>
<tr class="projection-description"><td><span>another badge</span></td></tr>
<tr class="projection-description"><td><span class="verfied-badge">verified-badge</span></td></tr>
</table>
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201