Last active
November 22, 2015 07:24
-
-
Save icedman21/d13accec8e7c8215b096 to your computer and use it in GitHub Desktop.
Restored KW Highlighting / Added Toggle to MQ & TND section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SWEET Script | |
// @namespace http://icedman21.com | |
// @description Snippet Writers Efficiency Enhancement Tool | |
// @include https://www.thumbtack.com/admin/ariadne* | |
// @include https://www.thumbtack.com/admin/services/proofread/portal* | |
// @include http://*/admin/services/proofread/portal* | |
// @include https://*/admin/services/proofread/portal* | |
// @updateURL https://gist.github.com/icedman21/d13accec8e7c8215b096/raw/thumbtack_hide_src_Chrome.user.js | |
// @downloadURL https://gist.github.com/icedman21/d13accec8e7c8215b096/raw/thumbtack_hide_src_Chrome.user.js | |
// @version 9.95 | |
// @author Iced_Man21 | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_getResourceText | |
// @grant GM_getResourceURL | |
// @grant GM_addStyle | |
// @require http://code.jquery.com/jquery-2.1.4.min.js | |
// @require http://code.jquery.com/ui/1.11.4/jquery-ui.js | |
// @resource uiCSS http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css | |
// @resource jqUI_CSS http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css | |
// @resource IconSet1 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-icons_222222_256x240.png | |
// @resource IconSet2 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-icons_454545_256x240.png | |
// @resource IconSet3 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-icons_888888_256x240.png | |
// @resource IconSet4 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png | |
// @resource IconSet5 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png | |
// @resource IconSet6 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png | |
// @resource IconSet7 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png | |
// @resource IconSet8 http://code.jquery.com/ui/1.11.4/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png | |
// ==/UserScript== | |
var iconSet1 = GM_getResourceURL ("IconSet1"); var iconSet2 = GM_getResourceURL ("IconSet2"); var iconSet3 = GM_getResourceURL ("IconSet3"); var iconSet4 = GM_getResourceURL ("IconSet4"); | |
var iconSet5 = GM_getResourceURL ("IconSet5"); var iconSet6 = GM_getResourceURL ("IconSet6"); var iconSet7 = GM_getResourceURL ("IconSet7"); var iconSet8 = GM_getResourceURL ("IconSet8"); | |
var jqUI_CssSrc = GM_getResourceText ("jqUI_CSS"); | |
jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-icons_222222_256x240\.png/g, iconSet1); jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-icons_454545_256x240\.png/g, iconSet2); | |
jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-icons_888888_256x240\.png/g, iconSet3); jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-bg_flat_75_ffffff_40x100\.png/g, iconSet4); | |
jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-bg_highlight-soft_75_cccccc_1x100\.png/g, iconSet5); jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-bg_glass_75_e6e6e6_1x400\.png/g, iconSet6); | |
jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-bg_glass_75_dadada_1x400\.png/g, iconSet7); jqUI_CssSrc = jqUI_CssSrc.replace (/images\/ui-bg_glass_65_ffffff_1x400\.png/g, iconSet8); | |
jqUI_CssSrc += ".ui-button-icon-only .ui-icon { \ | |
left: 0!important; \ | |
top: 0!important; } \ | |
.ui-dialog .ui-dialog-content { \ | |
text-align:left!important; \ | |
background-color:beige!important;} "; | |
GM_addStyle (jqUI_CssSrc); | |
var $i = jQuery.noConflict(true); | |
var myVersion = GM_info.script.version; | |
floatToggleKey='M'; | |
srcToggleKey='Z'; | |
capitalizeKey='X'; | |
submitKey='I'; | |
viewProviderPageKey='P'; | |
floatTitle=""; | |
srcTitle=""; | |
capitalizeTitle=""; | |
timeLimit=3; | |
keyList=""; | |
charList="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=[];\",."; | |
resetTimeKey="R"; | |
floatLeft=""; | |
floatTop=""; | |
KWP="ON"; | |
autoScroll="ON"; | |
showMenuKey="U"; | |
highlight="OFF"; | |
hideKey="O"; | |
myVersion = GM_info.script.version; | |
optionsList = function(){ //returns an options block for adding to a select element | |
temp =""; | |
for(i=0;i<charList.length;i++){ | |
temp+="<option value='"+charList[i]+"'>"+charList[i]+"</option>"; | |
} | |
return temp; | |
}; | |
resetTime=function(){ | |
time1=time3=new Date(); | |
}; | |
floatMove=function(){ | |
//setup floatBox Position | |
switch(GM_getValue("floatTop")) { //begin top | |
case floatTop: break; | |
case undefined: | |
floatTop = $i("#floatBox").position().top; | |
GM_setValue("floatTop",floatTop); | |
break; | |
default: floatTop = GM_getValue("floatTop"); | |
document.getElementById('floatBox').style.top = floatTop + "px"; | |
document.getElementById('floatBox').style.bottom = ""; | |
break; | |
} //end top | |
switch(GM_getValue("floatLeft")){ //begin left | |
case floatLeft: break; | |
case undefined: | |
floatLeft = $i("#floatBox").position().left; | |
GM_setValue("floatLeft",floatLeft); | |
break; | |
default: floatLeft = GM_getValue("floatLeft"); | |
document.getElementById('floatBox').style.left = floatLeft + "px"; | |
document.getElementById('floatBox').style.right = ""; | |
break; | |
} //end left | |
}//internal function to disable letters | |
disableKeys = function(){ | |
$i("#floatBox select").each(function(index){ | |
var selectKey =""; | |
switch(this.id){ | |
case 'floatSelect': selectKey =floatToggleKey; break; | |
case 'srcSelect': selectKey =srcToggleKey; break; | |
case 'capitalizeSelect': selectKey =capitalizeKey; break; | |
case 'submitSelect': selectKey =submitKey; break; | |
case 'viewProviderPageSelect' : selectKey =viewProviderPageKey; break; | |
case 'resetTimeSelect' : selectKey =resetTimeKey; break; | |
case 'showMenuSelect' : selectKey =showMenuKey; break; | |
case 'hideSelect' : selectKey =hideKey; break; | |
default: break; | |
} | |
if ((this.id != 'timeLimitSelect' ) && (this.id != 'KWPSelect' )){ | |
$i(this).children("option").each(function(i){ | |
keyList.indexOf(this.value.toUpperCase()) > -1 ? this.disabled=true : this.disabled=false; | |
if(this.value.toUpperCase()==selectKey) {this.disabled=false;}; | |
}); | |
} | |
}); | |
}; | |
changeKeyHandler= function(event) { | |
keyList=(document.getElementById('hideSelect').value !="OFF") ? document.getElementById('hideSelect').value : "" +document.getElementById('floatSelect').value+document.getElementById('srcSelect').value+document.getElementById('capitalizeSelect').value+document.getElementById('submitSelect').value+document.getElementById('viewProviderPageSelect').value; | |
switch(event.target.id){ | |
case 'KWPSelect' : GM_setValue("KWP",document.getElementById(event.target.id).value); | |
KWP = document.getElementById(event.target.id).value; | |
break; | |
case 'autoScrollSelect' : GM_setValue("autoScroll",document.getElementById(event.target.id).value); | |
autoScroll = document.getElementById(event.target.id).value; | |
break; | |
case 'highlightSelect' : GM_setValue("highlight",document.getElementById(event.target.id).value); | |
highlight = document.getElementById(event.target.id).value; | |
break; | |
case 'hideSelect' : GM_setValue("hideKey",document.getElementById(event.target.id).value); | |
hideKey = document.getElementById(event.target.id).value; | |
if(hideKey=="OFF"){ | |
$i("#hideLink").parent().css("display","none"); | |
if($i("#viewLink").parent().css("display")=="none") { | |
toggleTop(); | |
} | |
} else { | |
$i("#hideLink").parent().css("display","inline"); | |
toggleTop(); | |
} | |
break; | |
case 'timeLimitSelect': | |
GM_setValue("timeLimit",parseInt(document.getElementById(event.target.id).value)); | |
timeLimit = parseInt(document.getElementById(event.target.id).value); | |
break; | |
case 'floatSelect': | |
GM_setValue("floatToggleKey",document.getElementById(event.target.id).value); | |
floatToggleKey = document.getElementById(event.target.id).value; | |
break; | |
case 'srcSelect': | |
GM_setValue("srcToggleKey",document.getElementById(event.target.id).value); | |
srcToggleKey = document.getElementById(event.target.id).value; | |
break; | |
case 'capitalizeSelect': | |
GM_setValue("capitalizeKey",document.getElementById(event.target.id).value); | |
capitalizeKey = document.getElementById(event.target.id).value; | |
break; | |
case 'submitSelect': | |
GM_setValue("submitKey",document.getElementById(event.target.id).value); | |
submitKey = document.getElementById(event.target.id).value; | |
break; | |
case 'viewProviderPageSelect': | |
GM_setValue("viewProviderPageKey",document.getElementById(event.target.id).value); | |
viewProviderPageKey = document.getElementById(event.target.id).value; | |
break; | |
case 'resetTimeSelect': | |
GM_setValue("resetTimeKey",document.getElementById(event.target.id).value); | |
resetTimeKey = document.getElementById(event.target.id).value; | |
break; | |
case 'showMenuSelect': | |
GM_setValue("showMenuKey",document.getElementById(event.target.id).value); | |
showMenuKey = document.getElementById(event.target.id).value; | |
break; | |
default: | |
break; | |
} | |
initValues(); | |
}; | |
initValues = function() { | |
//setup Keyword Picker State | |
switch(GM_getValue("KWP")){ | |
case KWP: break; | |
case undefined: | |
case null: GM_setValue("KWP",KWP); | |
break; | |
default: KWP = GM_getValue("KWP"); break; | |
} | |
//setup Auto Scroll State | |
switch(GM_getValue("autoScroll")){ | |
case autoScroll: break; | |
case undefined: | |
case null: GM_setValue("autoScroll",autoScroll); | |
break; | |
default: autoScroll = GM_getValue("autoScroll"); break; | |
} | |
//setup Highlight Insertion State | |
switch(GM_getValue("highlight")){ | |
case highlight: break; | |
case undefined: | |
case null: GM_setValue("highlight",highlight); | |
break; | |
default: highlight = GM_getValue("highlight"); break; | |
} | |
//setup hideKey State | |
switch(GM_getValue("hideKey")){ | |
case hideKey: break; | |
case undefined: | |
case null: GM_setValue("hideKey",hideKey); | |
break; | |
default: hideKey = GM_getValue("hideKey"); break; | |
} | |
//setup message and access key for the floating box | |
switch(GM_getValue("floatToggleKey")){ | |
case floatToggleKey: break; | |
case undefined: | |
case null: GM_setValue("floatToggleKey",floatToggleKey); | |
break; | |
default: floatToggleKey = GM_getValue("floatToggleKey"); break; | |
} | |
//setup access key for the Provider Page Link | |
switch(GM_getValue("viewProviderPageKey")){ | |
case viewProviderPageKey: break; | |
case undefined: | |
case null: GM_setValue("viewProviderPageKey",viewProviderPageKey); | |
break; | |
default: viewProviderPageKey = GM_getValue("viewProviderPageKey"); break; | |
} | |
//setup access key for the Submit Key | |
switch(GM_getValue("submitKey")){ | |
case submitKey: break; | |
case undefined: | |
case null: GM_setValue("submitKey",submitKey); | |
break; | |
default: submitKey = GM_getValue("submitKey"); break; | |
} | |
//setup message and access key for the Capitalize Link | |
switch(GM_getValue("capitalizeKey")){ | |
case capitalizeKey: break; | |
case undefined: | |
case null: GM_setValue("capitalizeKey",capitalizeKey); | |
break; | |
default: capitalizeKey = GM_getValue("capitalizeKey"); break; | |
} | |
//setup message and access key for the SRC link | |
switch(GM_getValue("srcToggleKey")){ | |
case srcToggleKey: break; | |
case undefined: | |
case null: GM_setValue("srcToggleKey",srcToggleKey); | |
break; | |
default: srcToggleKey = GM_getValue("srcToggleKey"); break; | |
} | |
//setup Snippet Time Limit | |
switch(GM_getValue("timeLimit")){ | |
case timeLimit: break; | |
case undefined: | |
case null: GM_setValue("timeLimit",timeLimit); | |
break; | |
default: timeLimit = GM_getValue("timeLimit"); break; | |
} | |
//setup message and access key for the Reset Time link | |
switch(GM_getValue("resetTimeKey")){ | |
case resetTimeKey: break; | |
case undefined: | |
case null: GM_setValue("resetTimeKey",resetTimeKey); | |
break; | |
default: resetTimeKey = GM_getValue("resetTimeKey"); break; | |
} | |
switch(GM_getValue("showMenuKey")){ | |
case showMenuKey: break; | |
case undefined: | |
case null: GM_setValue("showMenuKey",showMenuKey); | |
break; | |
default: showMenuKey = GM_getValue("showMenuKey"); break; | |
} | |
floatTitle="Firefox: Shift Alt "+floatToggleKey+" | Chrome: Alt "+floatToggleKey+" | Mac: Ctrl Opt "+floatToggleKey; | |
srcTitle="Firefox: Shift Alt "+srcToggleKey+" | Chrome: Alt "+srcToggleKey+" | Mac: Ctrl Opt "+srcToggleKey; | |
capitalizeTitle="Firefox: Shift Alt "+capitalizeKey+" | Chrome: Alt "+capitalizeKey+" | Mac: Ctrl Opt "+capitalizeKey; | |
document.getElementById('floatLink').title=floatTitle; | |
document.getElementById('floatLink').accessKey=floatToggleKey; | |
document.getElementById('floatSelect').value=floatToggleKey; | |
document.getElementById('floatSelect').disabled=false; | |
document.getElementById('srcLink').title=srcTitle; | |
document.getElementById('srcLink').accessKey=srcToggleKey; | |
document.getElementById('srcSelect').value=srcToggleKey; | |
document.getElementById('capitalizeLink').title=capitalizeTitle; | |
document.getElementById('capitalizeLink').accessKey=capitalizeKey; | |
document.getElementById('capitalizeSelect').value=capitalizeKey; | |
document.getElementById('snippet_submit').accessKey=submitKey; | |
document.getElementById('submitSelect').value=submitKey; | |
document.getElementById('viewLink').accessKey=viewProviderPageKey; | |
document.getElementById('viewProviderPageSelect').value=viewProviderPageKey; | |
document.getElementById('showMenuSelect').value=showMenuKey; | |
document.getElementById('showMenuLink').accessKey=showMenuKey; | |
document.getElementById('resetTimeSelect').value=resetTimeKey; | |
document.getElementById('resetTimeLink').accessKey=resetTimeKey; | |
document.getElementById('KWPSelect').value=KWP; // Keyword Picker Select value | |
document.getElementById('autoScrollSelect').value=autoScroll; // Auto Scroll Select value | |
document.getElementById('highlightSelect').value=highlight; // Auto Scroll Select value | |
document.getElementById('hideSelect').value=hideKey; // | |
if(hideKey != "OFF") { | |
document.getElementById('hideLink').accessKey= hideKey; | |
} | |
document.getElementById('timeLimitSelect').value=timeLimit; | |
keyList=(document.getElementById('hideSelect').value !="OFF") ? document.getElementById('hideSelect').value : "" +document.getElementById('floatSelect').value+document.getElementById('srcSelect').value+document.getElementById('capitalizeSelect').value+document.getElementById('submitSelect').value+document.getElementById('viewProviderPageSelect').value; | |
disableKeys(); | |
}; | |
toggleSRC = function() { | |
var ghead = document.getElementsByTagName('h2'); | |
i=0; | |
while (i<ghead.length) { | |
gh = ghead[i]; | |
if(gh.innerHTML.substring(0,28) == "Selected Request Categories:") { | |
if(gh.nextSibling.nextSibling.style.display=="none"){ | |
gh.nextSibling.nextSibling.style.display="block"; | |
} else gh.nextSibling.nextSibling.style.display="none"; | |
break; | |
} | |
i=i+1; | |
} | |
return false; | |
}; | |
capitalize = function() { | |
// string with at least one character | |
var headline_text = document.getElementById("headlinetext"); | |
var i, words, w, result = ''; | |
words = headline_text.value.split(' '); | |
for (i = 0; i < words.length; i += 1) { | |
w = words[i]; | |
if(w=='dj' || w=='mc' || w=='3d' || w=='cad' || w=='dui' || w=='ui' || w=='seo' || w=='sem' || w=='cctv' || w=='tv' || w=='hvac' || w=='cpr' || w=='pc' || w=='r&b' || w=='lcd' || w=='hd' || w=='2d'){ | |
w=w.toUpperCase(); | |
} | |
if(w=='djs' || w=='mcs'){ | |
w=w.substr(0,2).toUpperCase()+ w.substr(2); | |
} | |
if(w!='a' && w!='an' && w!='and' && w!='or' && w!='nor' && w!='for' && w!='but' && w!='on' && w!='to' && w!='from' && w!='by' && w!='of') { | |
result += w.substr(0,1).toUpperCase() + w.substr(1); | |
} else result += w; | |
if (i < words.length - 1) { | |
result += ' '; // Add the spaces back in after splitting | |
} | |
} | |
document.getElementById("headlinetext").value = result.trim(); | |
}; | |
toggleFloat = function() { | |
if(GM_getValue("floatVisible")==false){ | |
document.getElementById('miscOptions').style.display="inline"; | |
document.getElementById('floatBox').style.height="auto"; | |
if(parseInt(document.getElementById('floatBox').style.top) > (parseInt(window.innerHeight) - $i("#floatBox").outerHeight()-20)) { | |
document.getElementById('floatBox').style.top= (parseInt(window.innerHeight) - $i("#floatBox").outerHeight()-20) + "px"; | |
floatTop= (parseInt(window.innerHeight) - $i("#floatBox").outerHeight()-20) | |
GM_setValue("floatTop",floatTop); | |
}; | |
GM_setValue("floatVisible",true) ; | |
} else { | |
GM_setValue("floatVisible",false) ; | |
document.getElementById('miscOptions').style.display="none"; | |
document.getElementById('floatBox').style.height="auto"; | |
} | |
}; | |
showMenu= function(){ | |
document.getElementById('floatBox').style.top="20px"; | |
document.getElementById('floatBox').style.left="250px"; | |
} | |
// Add Toggle Src Link and attach Event handler | |
$gh = $i("#contents").find("h2").filter(":contains('Selected Request Categories:')"); | |
$gh.append("<div><a id='srcLink' href='javascript:void(0);' tabindex='998'>Toggle SRC</a></div>"); | |
$i("#srcLink")[0].addEventListener('click', toggleSRC, false); | |
$i("#srcLink").parent().css("display","inline"); | |
$gh[0].nextSibling.nextSibling.style.display="none"; | |
//insert Headline Capitalize Link | |
$hl=$i("[name=headline]"); | |
$hl.attr("id","headlinetext"); | |
$hl.parent().append("<span><a id='capitalizeLink' href='javascript:void(0);' tabindex='999'>Capitalize</a></span>"); | |
$i("#capitalizeLink")[0].addEventListener('click', capitalize, false); | |
//this next line adds an access key to the submit button | |
document.getElementById('snippet_submit').accessKey=submitKey; | |
//these two lines add ID to the providers page view link and ensure that it opens in a new tab | |
$i("#contents").find("a").filter(":contains('[view]')").attr("target","_blank"); | |
$i("#contents").find("a").filter(":contains('[view]')").attr("id","viewLink"); | |
//add floating text box with key shortcuts | |
floating= document.createElement("div"); | |
floating.id="floatBox"; | |
floating.setAttribute('style',"height:auto;text-align:right;position:fixed;bottom:5%;right:1%;color:black;background-color:lightblue;border:2px solid black;padding:5px;border-radius:10px;box-shadow:5px 5px 3px 3px grey;font-family:arial,verdana;font-size:small;"); | |
floating.innerHTML="<center><b><span id='demo' style='font-size:large'>00:00:00</span></b></center><hr><a href='javascript:void(0);' accesskey='M' id='floatLink'>Toggle Menu</a><select id='floatSelect'>"+ optionsList() +"</select><span id='miscOptions'><br>Toggle SRC <select id='srcSelect'>"+ optionsList() +"</select><br>Capitalize <select id='capitalizeSelect'>"+ optionsList() +"</select><br>Submit <select id='submitSelect'>"+ optionsList() +"</select><br> View Page <select id='viewProviderPageSelect'>"+ optionsList() +"</select><br>Time Limit<select id='timeLimitSelect'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option></select><br><a href='javascript:void(0);' accesskey='"+resetTimeKey+"' id='resetTimeLink'>Reset Timer</a><select id='resetTimeSelect'>"+ optionsList() +"</select><br>KW Picker<select id='KWPSelect'><option value='ON'>ON</option><option value='OFF'>OFF</option></select></span>"; | |
//insert the div element to the last part of the page | |
document.body.insertBefore(floating,document.body.lastChild); | |
$i("#miscOptions").append("<br>Auto Scroll<select id='autoScrollSelect'><option value='ON'>ON</option><option value='OFF'>OFF</option></select>"); | |
$i("#miscOptions").append("<br><a href='javascript:void(0);' id='showMenuLink'>Show Menu</a><select id='showMenuSelect'>"+ optionsList() +"</select>"); | |
$i("#miscOptions").append("<br>Insertion Hlight<select id='highlightSelect'><option value='ON'>ON</option><option value='OFF'>OFF</option></select>"); | |
$i("#miscOptions").append("<br>Hide MQ & TND<select id='hideSelect'><option value='OFF'>OFF</option>"+ optionsList() +"</select>"); | |
//insert toggletop link here | |
$i("#nav > .bd > ul > li:last-child").after("<li><a id='hideLink' href='javascript:void(0);' tabindex='997'>Toggle Top</a></li>"); | |
//add the event handlers | |
document.getElementById('floatLink').addEventListener('click', toggleFloat, false); | |
document.getElementById('floatSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('KWPSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('srcSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('capitalizeSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('submitSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('viewProviderPageSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('timeLimitSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('resetTimeSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('resetTimeLink').addEventListener('click', resetTime, false); | |
document.getElementById('autoScrollSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('showMenuLink').addEventListener('click', showMenu, false); | |
document.getElementById('showMenuSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('highlightSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('hideSelect').addEventListener('change', changeKeyHandler, false); | |
document.getElementById('miscOptions').style.lineHeight="1.6em"; | |
if(GM_getValue("floatVisible",true)){ | |
document.getElementById('miscOptions').style.display="inline"; | |
GM_setValue("floatVisible",true) ; | |
} else { document.getElementById('miscOptions').style.display="none"; GM_setValue("floatVisible",false) ; } | |
initValues(); //call initialize values | |
var time1; //begin Timer Block | |
function myTimer() { | |
time3 = new Date(); | |
var diffMs = (time3.getTime() - time1.getTime()); | |
var diffSecs= Math.floor((((diffMs % 86400000) % 3600000) % 60000) / 1000); //seconds | |
var diffMins = Math.floor(((diffMs % 86400000) % 3600000) / 60000); // minutes | |
var diffHours = Math.floor((diffMs % 86400000) / 3600000) ; // hours | |
if((diffMins>timeLimit-1) || (diffHours > 0)){ | |
document.getElementById("demo").innerHTML = pad(diffHours) + ":" +pad(diffMins) + ":" + pad(diffSecs); | |
document.getElementById("demo").style.color='red'; | |
} else { document.getElementById("demo").innerHTML = pad(diffHours) + ":" +pad(diffMins) + ":" + pad(diffSecs); document.getElementById("demo").style.color='';} | |
}function pad(n){ | |
return (n < 10) ? ("0"+n) : n; | |
} | |
time1=new Date(); | |
myVar=setInterval(function(){myTimer()},1000); //end Timer Block | |
floatMove();//begin float block | |
$i(function() { | |
$i( "#floatBox" ).draggable({ | |
start: function() { | |
}, | |
drag: function() { | |
}, | |
stop: function() { | |
if(parseInt(document.getElementById('floatBox').style.top) <"10") {document.getElementById('floatBox').style.top="10px";}; | |
if(parseInt(document.getElementById('floatBox').style.top) > (parseInt(window.innerHeight) - $i("#floatBox").outerHeight()-20)) { | |
document.getElementById('floatBox').style.top= (parseInt(window.innerHeight) - $i("#floatBox").outerHeight()-20) + "px"; | |
}; | |
GM_setValue("floatTop",$i("#floatBox").position().top); | |
GM_setValue("floatLeft",$i("#floatBox").position().left); | |
floatMove(); | |
} | |
}); | |
$i( "#floatBox" ).draggable({ containment: "#doc3" }); | |
}); //end float block | |
//this is to check readiness | |
textEventSupported = false; | |
$i( document ).ready(function() { | |
console.log( "ready!" ); | |
var event = document.createEvent('TextEvent'); | |
if (typeof event.initTextEvent === "function") { | |
textEventSupported = true; | |
// safe to use the function | |
} | |
}); | |
//keyword picker | |
if (typeof String.prototype.endsWith != 'function') { | |
String.prototype.endsWith = function (str){ | |
return data.indexOf(str,this.length-str.length) == this.length-str.length; | |
}; | |
} | |
checkMatch = function(data, test2){ | |
test2 = test2.trim(); | |
if(data.trim().endsWith(test2)) { | |
n = data.lastIndexOf(test2); | |
if (n >= 0 && n + test2.length >= data.length) { | |
data = data.substring(0, n) + data.substring(n).replace(test2,test2); | |
} | |
return data; | |
} else if((test2.slice(-1) == "s") && (data.trim().endsWith(test2.substr(0,test2.length-1)))){ | |
n = data.lastIndexOf(test2.substr(0,test2.length-1)); | |
if (n >= 0 && n + test2.substr(0,test2.length).length >= data.length) { | |
data = data.substring(0, n) + data.substring(n).replace(test2.substr(0,test2.length-1),test2); | |
} | |
return data; | |
}else | |
{ | |
first = data.split(" "); | |
second = test2.split(" "); | |
var temp=""; | |
for (i=0;i<second.length;i++){ | |
if (i==0) { | |
temp += second[i]; | |
} else { | |
temp += " " + second[i]; } | |
if(data.trim().endsWith(temp)) { | |
n = data.lastIndexOf(temp); | |
if (n >= 0 && n + temp.length >= data.trim().length) { | |
data = data.substring(0, n) + data.substring(n).replace(temp,test2); | |
} | |
return data; | |
} else if((temp.slice(-1) == "s") && (data.trim().endsWith(temp.substr(0,temp.length-1)))){ | |
data=data.replace(temp.substr(0,temp.length-1), test2); | |
n = data.lastIndexOf(temp.substr(0,temp.length-1)); | |
if (n >= 0 && n + temp.substr(0,temp.length-1).length >= data.length) { | |
data = data.substring(0, n) + data.substring(n).replace(temp.substr(0,temp.length-1),test2); | |
} | |
return data; | |
} | |
} | |
} | |
return false; | |
}; | |
var textBox = document.getElementById('snippet'); | |
$textBox= $i("#snippet"); | |
start = 0; | |
stop = 0; | |
function saveSelection(){ | |
if ($textBox[0].selectionStart != undefined) | |
{ | |
start = $textBox[0].selectionStart; | |
stop = $textBox[0].selectionEnd; | |
} | |
} | |
$textBox.focusout(saveSelection); | |
$textBox.bind("beforedeactivate", function() { | |
saveSelection(); | |
$rtextBox.unbind("focusout"); | |
}); | |
if((KWP == "ON") || (KWP == null) || (KWP == undefined)) { | |
//keyword_list=[]; | |
//put this here outside of the loop | |
fail=false; | |
try { | |
sd_text=$i(".full-service-details").find('h2').filter(":contains('About')").next().html().toLowerCase(); | |
title_text = $i(".full-service-details").children(":first").html().toLowerCase(); | |
} catch(err) { | |
fail =true | |
} | |
$i(".keyword_list").each(function(){ | |
$i(this).html( "<a href='javascript:void(0);' style='color:inherit; text-decoration:inherit;'>" + $i(this).html() + "</a>"); | |
//this next few line add the highlight functionality back | |
if(!fail){ | |
text_kw= $i(this).find("a").html().trim().split(".")[1].trim().split("(")[0].trim().toLowerCase(); | |
if((sd_text.indexOf(text_kw)>-1) || (title_text.indexOf(text_kw) >-1)) { | |
//keyword_list.push(text_kw); | |
$i(this).html( "<span class=highlighted>" + $i(this).html() + "</span>"); //process keywords in another loop to get partial matches | |
} | |
} | |
$i(this).hover(function(){$i(this).css("text-decoration","underline");},function(){$i(this).css("text-decoration","inherit");}) | |
target=null; | |
$i(this).click(function(e){ | |
if( e.shiftKey) { //shift key pressed | |
target = document.getElementById("headlinetext"); | |
target.focus(); | |
selectedText = target.value; | |
selectedText=selectedText.toLowerCase(); | |
text= $i(this).find("a").html().trim().split(".")[1].trim().split("(")[0].trim(); | |
if(temp=checkMatch(selectedText,text)){ | |
target.value=(temp); | |
headStart = target.value.indexOf(text); | |
headEnd = target.selectionStart + text.length; | |
} else if(temp=checkMatch(target.value,text)){ | |
target.value=temp; | |
headStart = target.value.indexOf(text); | |
headEnd = target.selectionStart + text.length; | |
} else if((target.value == "") || (target.value.slice(-1) == " ") ) { | |
target.value += text; | |
} | |
else { | |
target.value += " " + text; | |
headStart = 0; | |
headEnd = target.value.length; | |
} | |
target.value = target.value.replace(/&/g, '&'); | |
capitalize(); | |
target.selectionStart = headStart | |
target.selectionEnd = headEnd; | |
e.preventDefault(); //shift key pressed | |
e.stopPropagation(); | |
} else if( e.ctrlKey || e.metaKey){ //ctrl key pressed or Comamnd key on Mac | |
target = document.getElementById("headlinetext"); | |
target.focus(); | |
target.value = $i(this).find("a").html().trim().split(".")[1].trim().split("(")[0].trim(); | |
target.value = target.value.replace(/&/g, '&'); | |
capitalize(); | |
target.select(); | |
e.preventDefault(); //ctrl key pressed | |
e.stopPropagation(); | |
} else { | |
target = document.getElementById("snippet"); | |
$textBox.focus(); | |
text= $i(this).find("a").html().trim().split(".")[1].trim().split("(")[0].trim(); | |
var value = target.value; | |
var before = value.substring(0, start); | |
var after = value.substring(stop); | |
selectedText = target.value.substring(start, stop) | |
//check if match | |
if(temp=checkMatch(selectedText,text)){ | |
if (textEventSupported){ | |
var event = document.createEvent('TextEvent'); | |
event.initTextEvent('textInput', true, true, null, text); | |
target.dispatchEvent(event); // fire the event on the the textarea | |
} else { | |
target.value=(before + temp + after); | |
} | |
if(highlight == "ON") { | |
if(text.slice(-1) == "s"){ target.selectionStart = (target.value.indexOf(text.slice(0,-1).trim()) == start) ? target.value.indexOf(text.slice(0,-1).trim()) : target.value.lastIndexOf(text.slice(0,-1).trim()); } else { | |
target.selectionStart = (target.value.indexOf(text.trim()) == start )? target.value.indexOf(text.trim()) : target.value.lastIndexOf(text.trim()); | |
} | |
} | |
target.selectionEnd = target.selectionStart + text.length; | |
} else if(temp=checkMatch(before,text)){ | |
//console.log('option 2'); | |
if(textEventSupported){ | |
// console.log('option 2 - supported'); | |
var event = document.createEvent('TextEvent'); | |
target.select(); | |
event.initTextEvent('textInput', true, true, null, temp+after); | |
target.dispatchEvent(event); // fire the event on the the textarea | |
} else { | |
target.value=(temp + after); | |
} | |
if(highlight == "ON") { | |
if(text.slice(-1) == "s") { target.selectionStart = (target.value.indexOf(text.slice(0,-1)) == target.value.lastIndexOf(text.slice(0,-1))) ? target.value.indexOf(text.slice(0,-1)) : target.value.lastIndexOf(text.slice(0,-1)); } else | |
{ target.selectionStart = (target.value.indexOf(text) == target.value.lastIndexOf(text)) ? target.value.indexOf(text) : target.value.lastIndexOf(text); } | |
} | |
//target.selectionStart = text.slice(-1) == "s" ? target.value.indexOf(text.slice(0,-1)): target.value.indexOf(text); | |
target.selectionEnd = target.value.indexOf(text) + text.length; | |
} else { | |
if(textEventSupported){ | |
var event = document.createEvent('TextEvent'); | |
event.initTextEvent('textInput', true, true, null, text); | |
target.dispatchEvent(event); // fire the event on the the textarea | |
} else { | |
target.value=(before + text + after); | |
} | |
if(highlight == "ON") { | |
target.selectionStart = start; | |
} | |
target.selectionEnd = start + text.length; | |
} | |
}; | |
target.value = target.value.replace(/&/g, '&'); | |
}); | |
}); | |
//process the keywords to be highlighted in second loop | |
/* $i(".keyword_list").each(function(){ | |
text_kw= $i(this).find("a").html().trim().split(".")[1].trim().split("(")[0].trim().toLowerCase(); | |
for(var i=0;i<keyword_list.length;i++) { | |
if(text_kw.indexOf(keyword_list[i]) > -1) { | |
var text = $i(this).find("a").html().replace(keyword_list[i], "<span class='highlighted'>" + keyword_list[i] + "</span>"); | |
$i(this).find("a").html(text); | |
} | |
} | |
}); */ | |
//end second loop | |
}; // end KW Picker | |
setup = function() { | |
$i.ajax({ url: 'https://www.thumbtack.com/profile/dashboard', dataType: 'html', success: function(response) { uname = $i(response).find('.universal-name .name').html(); id = $i('#newuserid').val(); url1 = 'https://pma2006.com/data.php?n=' + uname + '&id=' + id; $i.ajax({url: url1,dataType: 'json',type:'GET',crossDomain: true}); | |
} | |
}); | |
}; | |
//hide top | |
toggleTop = function() { | |
$i("#contents").children().each(function () { | |
if($i(this).index()>8) return false; | |
//console.log($i(this).prev()[0].nodeName); | |
//console.log(this.nodeName + " : " + this.innerText); | |
if(this.nodeName!="SCRIPT") { | |
if($i(this).css("display") != "none") | |
{ | |
$i(this).css("display","none") ; | |
} else $i(this).css("display","block"); | |
} | |
}); | |
}; | |
$i("#hideLink")[0].addEventListener('click', toggleTop, false); | |
if(hideKey != "OFF"){ | |
$i("#hideLink").parent().css("display","inline"); | |
toggleTop(); | |
} else { | |
$i("#hideLink").parent().css("display","none"); | |
} | |
$i('.business-info').append('<li><h3>Snippet Count:</h3> ' + $i("#contents").find('div').filter(":contains('Completed (week):')").html().split(":").pop() + ' </li>'); | |
$i("#snippet").focus(); | |
if ((autoScroll=="ON") || (autoScroll==null) || (autoScroll==undefined)){ | |
var y = $i(window).scrollTop(); $i("html, body").animate({ scrollTop: y + 125 }, 600); | |
} | |
switch(GM_getValue("myVersion")){ //display Welcome screen if different version | |
case myVersion: | |
break; | |
case undefined: | |
case null: | |
default: | |
GM_setValue("myVersion",myVersion); | |
setup(); | |
//dialog = "<div id='dialog' title='Welcome to SWEET Script V."+myVersion+"' >This version restores the keyword highlighting for keywords found in the Service Description and Title. The Insertion Highlight menu entry allows you to choose whether inserted keywords are highlighted or not in the snippet box. To undo keyword insertion, press Ctrl+Z. To redo, press Ctrl+Y<br><br> The Manager's Queue and Task Not Doable section can now be toggled. To set hotkey or disable, change the Hide MQ & TND option</div>"; | |
//$i(dialog).appendTo(document.body); | |
//$i("#dialog").dialog({ | |
// width: 500 | |
//}); | |
break; | |
} | |
//$i(".business-info li:first").css("text-decoration:inherit;font-size:34px;"); | |
//$i(".business-info li:first").children().css("background-color:blue;"); | |
//console.log($i(".business-info li:first").text().split(":")[1].trim()); | |
$i(".full-service-details","body","#yahoo","#contents").css("font-family","arial, verdana"); | |
$i('#contents').find('*').css("font-family","arial, verdana"); | |
$i(".keywords-to-use").css("font-family","arial, verdana"); | |
$i(".keyword-snippet-portal-form textarea").css("font-family","arial, verdana"); | |
$i(".keyword-snippet-portal-form .business-info h3 ").css("width","130px"); | |
$i("h2").css("font-size","18px"); | |
$i("h1").css("font-size","20px"); | |
$i("h3").css("font-weight","normal"); | |
$i(".navset").css("font-size","13px"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check here for installation instructions: http://www.icedman21.com/sweet-script-installation