Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Yoder
- // @author Sasquatch
- // @version 1.0.0
- // @namespace http://www.turksquatch.com/
- // @homepage http://www.turksquatch.com/
- // @description Tame the internet.
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
- // @include https://www.mturkcontent.com/*
- // @include https://www.google.com/*
- // @grant none
- // ==/UserScript==
- //to do - highlight search term, add functionality to given domain
- var autosubmit = false;
- String.prototype.strip_html = function() {
- var tmp = document.createElement('div');
- tmp.innerHTML = this;
- return tmp.textContent || tmp.innerText;
- }
- function copyText(evt) {
- if (evt.keyCode == 59 && evt.ctrlKey) {
- var selectedText = getText();
- if (selectedText && selectedText != '') {
- sendText(selectedText);
- } else {
- alert('Nothing selected');
- }
- }
- if (evt.keyCode == 222 && evt.ctrlKey) {
- sendText("N/A");
- }
- }
- function getText() {
- var userSelection = '';
- if (typeof window.getSelection != 'undefined') {
- var sel = window.getSelection();
- if (sel.rangeCount) {
- var container = document.createElement('div');
- for (var i = 0, len = sel.rangeCount; i < len; ++i) {
- container.appendChild(sel.getRangeAt(i).cloneContents());
- }
- userSelection = container.innerHTML.strip_html();
- }
- } else if (typeof document.selection != 'undefined') {
- if (document.selection.type == 'Text') {
- userSelection = document.selection.createRange().htmlText.strip_html();
- }
- }
- return userSelection;
- }
- function sendText(textVar) {
- window.opener.postMessage({ securitycheck: "fromgooglesearch", dataval: textVar }, "*");
- }
- function highlightTerm(term) {
- $('#ires>*').each(function(){
- if ($(this).html().indexOf(term) > -1) {
- var regex = new RegExp(term, 'gi');
- $(this).html($(this).html().replace(regex ,'<span style=\'background:yellow\'>'+term+'</span>' ));
- }
- });
- }
- if (window.location.href.indexOf('mturkcontent') > -1) {
- document.getElementById('mturk_form').onsubmit = function() {
- searchWin.close();
- }
- window.addEventListener('message', function(e) {
- if (e.data.securitycheck === 'fromgooglesearch') {
- self.focus();
- document.getElementById('web_url').focus();
- document.getElementById('web_url').value = e.data.dataval;
- if (autosubmit) {
- document.getElementById('mturk_form').submit();
- }
- }
- }, false);
- var domainName = document.getElementsByTagName('td')[1].innerHTML.trim();
- var directUrl = 'http://' + domainName;
- var googleBase = 'https://www.google.com/search?q=';
- var queryString = encodeURIComponent(domainName);
- var searchUrl = googleBase + queryString;
- var w = screen.availWidth/2;
- var h = screen.availHeight;
- searchWin = window.open(searchUrl, 'Search Page', 'width='+w+', height='+h+', scrollbars=yes, toolbar=yes');
- searchWin.moveTo(w,0);
- } else {
- if (window.location.href.indexOf('google.com') > -1) {
- var searchTerm = window.location.href.split('q=')[1].split('&')[0];
- }
- highlightTerm(searchTerm);
- document.onkeydown = copyText;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement