Discussions » Développement

modifying Google Search to make results intentionally inaccurate

§
Posté le: 2014-08-25
Édité le: 2014-09-13

modifying Google Search to make results intentionally inaccurate

I already made a post at Superuser http://superuser.com/questions/800325/how-to-make-google-search-look-dumb

I will summarize here:

[1] http://i.stack.imgur.com/ZN60B.jpg

My point is I do not want to see torrent sites in the search results,so if someone searches Google or YouTube this phrase(-torrent-download-watch) should be automatically and invisibly added.

[2] http://i.stack.imgur.com/4mUSt.jpg

And one of the answers was this userscript written by krowe:

// ==UserScript==
// @name Tamper with Google Results
// @namespace http://superuser.com/users/145045/krowe
// @version 0.1
// @description This just modifies google results to exclude certain things.
// @match http://*.google.com
// @match https://*.google.com
// @copyright 2014+, KRowe
// ==/UserScript==


function GM_main () {
window.onload = function () {
var targ = window.location;
if(targ && targ.href && targ.href.match('https?:\/\/www.google.com/.+#q=.+') && targ.href.search("/+-torrent/+-watch/+-download")==-1) {
targ.href = targ.href +"+-torrent+-watch+-download";
}
};
}

//-- This is a standard-ish utility function:
function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
var D=document, scriptNode = D.createElement('script');
if(runOnLoad) scriptNode.addEventListener("load", runOnLoad, false);
scriptNode.type = "text/javascript";
if(text) scriptNode.textContent = text;
if(s_URL) scriptNode.src = s_URL;
if(funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
targ.appendChild(scriptNode);
}

addJS_Node (null, null, GM_main);


But the script is not working at all. I copied it to tampermonkey , tried it several times no luck.I need some help please.


Thank you in advance.

This script seems designed to tack on the following at the end of the URL:

+-torrent+-watch+-download

Does it do that?

I think the problem with that approach could be that the query string seldom is the last thing in the URL, so the script is feeding it into a completely unrelated parameter.

If you only want this for Chrome, could I suggest creating a custom search engine in Chrome's settings?

Open: chrome://settings/searchEngines

In the row of empty boxes, enter a name (e.g., Google No Torrents) and keyword, then in the search box paste this:

{google:baseURL}search?q=%s+-torrent+-watch+-download

Click out of that last box and Chrome should save the new search engine. Then mouse over it and click the Make Default button on the right side. Now you can test a search in the address bar.

Unfortunately, this doesn't work from Google's home page, so you would still need a script to modify searches done from there if you prefer that.

I didn't look at the SuperUser thread before.

I don't think there is a way to hide any part of the query from the normal results page. However, Google Custom Search Engines (CSE) may be able to do it.

§
Posté le: 2014-08-25

first of all thank you for your answer.

My aim is to block torrent sites from google search results.I don't want others(family members) to notice the tampering.I have looked into other solutions, using MITM proxy like Fiddler,but I need someone to write me a script in JScript.NET.Perphaps I can hire someone(Mr.Jefferson Scher, are you interested? I will pay you)

Looking foward for your reply.

Fiddler is hard to use with secure sites, at least in Firefox. That doesn't rule it out as an option, but you might want to test with some other scripts first to make sure it won't generate a lot of errors during normal browsing.

Someone could adapt my script Google Hit Hider to check the entire result (title, URL, text snippet) for forbidden words and hide the result. Those you are trying to fool might become suspicious, though, if Google seems to be returning a random number of results on each page.

§
Posté le: 2014-08-26

About Google Hit Hider,Is there a way to use wildcards or regular expressions to perma ban torrent sites?

The script currently does not support wildcards or regular expressions in domain names. That would require significant changes by someone more skilled with RegEx than I am.

§
Posté le: 2014-08-29
Édité le: 2014-08-29

"I don't think there is a way to hide any part of the query from the normal results page"

I got this from http://stackoverflow.com/questions/2441565/how-do-i-make-a-div-element-editable-like-a-textarea-when-i-click-it#2441686

You can't make a div editable. There's no such thing as an editable div, at least for now. So the problem is finding out what to use for editing instead. A textarea works perfectly. So the idea is to somehow get a textarea where the div currently sits.

The question is how and from where do we get the textarea. There are various ways, but one of them is to dynamically create a textarea on the fly:
var editableText = $("");

and replace it with the div:
$("#myDiv").replaceWith(editableText);

The textarea is in place now. But it is empty and we have just replaced the div and lost everything. So we need to preserve the text of the div somehow. One way is to copy the text/html inside the div before replacing it:
var divHtml = $("#myDiv").html(); // or text(), whatever suits.

Once we have the html from the div, we can populate the textarea and safely replace the div with the textarea. And set the focus inside the textarea as the user might want to start editing. Combining all the work upto this point, we get:

// save the html within the div
var divHtml = $("#myDiv").html();
// create a dynamic textarea
var editableText = $("<textarea />");
// fill the textarea with the div's text
editableText.val(divHtml);
// replace the div with the textarea
$("#myDiv").replaceWith(editableText);
// editableText.focus();

It's functional but nothing happens when a user clicks a div because we didn't setup any events. Let's wire up the events. When the user clicks any div $("div").click(..), we create a click handler, and do all of the above.

$("div").click(function() {
var divHtml = $(this).html(); // notice "this" instead of a specific #myDiv
var editableText = $("<textarea />");
editableText.val(divHtml);
$(this).replaceWith(editableText);
editableText.focus();
});

This is good, but we'd want a way to get our div back when a user clicks out or leaves the textarea. There is a blur event for form controls that is triggered when a user leaves the control. That can be used to detect when a user leaves the textarea, and replace back the div. We do the exact reverse this time. Preserve the value of textarea, create a dynamic div, set it's html, and replace out the textarea.

$(editableText).blur(function() {
// Preserve the value of textarea
var html = $(this).val();
// create a dynamic div
var viewableText = $("<div>");
// set it's html
viewableText.html(html);
// replace out the textarea
$(this).replaceWith(viewableText);
});

Everything is great, except that this new div will no longer convert into a textarea on click. This is a newly created div, and we'll have to setup the click event again. We already have the entire code, but better than repeating it twice, it's better to make a function out of it.

function divClicked() {
var divHtml = $(this).html();
var editableText = $("<textarea />");
editableText.val(divHtml);
$(this).replaceWith(editableText);
editableText.focus();
// setup the blur event for this new textarea
editableText.blur(editableTextBlurred);
})

Since the whole operation is two-way reversible, we'll need to do the same for the textarea. Let's convert that into a function too.

function editableTextBlurred() {
var html = $(this).val();
var viewableText = $("<div>");
viewableText.html(html);
$(this).replaceWith(viewableText);
// setup the click event for this new div
$(viewableText).click(divClicked);
});

Wiring up everything together, we have 2 functions, divClicked, editableTextBlurred and the line below triggers everything:
$("div").click(divClicked);

Checkout this code at http://jsfiddle.net/GeJkU/. This is not the best way of writing editable divs by any means, but just one way to start and approach the solution step by step. Honestly I have learnt just as much as you in writing this long piece. Signing off, adios!

Can this solve my Google search problem?(I am not a programmer,so this is confusing to me)

woxxomMod
§
Posté le: 2014-08-29
Édité le: 2014-08-29

I would simply try modifying the google search url in settings of teh browser

§
Posté le: 2014-08-30

@wOxxOm Can you please give me an example?

woxxomMod
§
Posté le: 2014-08-30

@fere, apparently it depends on browser, for example in Chrome you'll have to make a copy of the default google search engine url to edit it; in Firefox you can either edit a copy of the searchplugin xml and set it as the default or use an extension (InstantFox, Organize Search Engines, etc) to edit the google search url.

The edit itself is simple: add +-torrent+-download+-watch or %20-torrent%20-download%20-watch to the search url right after q=%s or q=%q or q={searchTerms} etc.

§
Posté le: 2014-08-30

@wOxxOm I like it,now,how can I use css to add a blank white layer on top of the words in the textarea. Family members should not be aware,that's the main point.

Also if the above method does not work,Is there a different way we can approch.(already tried google cse,chrome's personal-blocklist; But my eyes are on Fiddler and privoxy)

woxxomMod
§
Posté le: 2014-08-30

@fere, that's tricky to implement I suppose since google uses ajax and events, but probably it'll be possible to set a document mutation observer which will hide the stuff in the search box before it's shown.

§
Posté le: 2014-08-30

@wOxxOm Are you familiar with using MITM proxy like fiddler,What line do I edit to remove links from the results

For example:I typed "whose line is it anyway" in the search box.

woxxomMod
§
Posté le: 2014-08-30

@fere, I think you can modify anything as this data blob already contains the search results, so it doesn't matter if you modify the search string. BTW maybe you can just add the filter words to the outgoing request and thus have everything done via Fiddler without touching the local files which could be reinstalled during an update?

§
Posté le: 2014-09-09
Édité le: 2014-09-09

@Jefferson Scher @wOxxOm Can this code solve my problem?

Question was"How to hide text present inside search box?"

var keywordInput = $('input[name="-adult"]');
$('input[name="SearchButton"]').click(function() {
window.location = 'http://example.com?kwd=' + encodeURIComponent(keywordInput.val());
});

More info:http://stackoverflow.com/a/25735187/3868650

@fere, I think name is the wrong attribute:

var keywordInput = $('input[name="-adult"]');

To find the input with -adult anywhere in the value you would need something along these lines (normal JavaScript, not jQuery syntax):

var keywordInput = document.querySelector('input[value*="-adult"]');

§
Posté le: 2014-09-13
Édité le: 2014-09-13

@Jefferson Scher : Slightly off-topic Javascript/fiddler question.

I’ve appended a string to the URL and when I keep issuing the request it keeps appending over and over again

In OnBeforeRequest function

if (oSession.uriContains("www.youtube.com/results?search_query=")) {

var sText = "+test1+test2+test3";

oSession.fullUrl = oSession.fullUrl + sText;
}

visual info: http://imgur.com/oRp24Ux,RvxtQTO,LniAECS#0

How can I fix this ?

Thank you for your time

§
Posté le: 2014-09-13
Édité le: 2014-09-13

I tried this, but doesnt work :

if (oSession.uriContains("www.youtube.com/results?search_query="))
{
var str = oSession.fullUrl;
var sAppend = "+test1+test2+test3";
if (oSession.fullUrl.indexOf(sAppend, str.length - sAppend.length) !== -1)
{
oSession.fullUrl = str + sAppend;
}
}

I'm not familiar with the Fiddler-specific parts.

I get consistent results for both of these pairs in the web console --

"thisisatest".indexOf("test") !== -1;

"thisisatest".indexOf("test", "thisisatest".length - "test".length) !== -1;

"thisisatest".indexOf("blah") !== -1;

"thisisatest".indexOf("blah", "thisisatest".length - "blah".length) !== -1;

-- so the JavaScript seems fine.

Poster une réponse

Connectez-vous pour poster une réponse.