-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchAndReplace.min.js
More file actions
1 lines (1 loc) · 8.75 KB
/
searchAndReplace.min.js
File metadata and controls
1 lines (1 loc) · 8.75 KB
1
javascript:{function Search(e,t,n){this.find=e;this.replace=t;this.numberOfReplaces=n;this.htmlNode=null;this.createNode=function(){var e=document.createElement("li");e.className="search-result";e.innerHTML='<span class="results-remove" onclick="removeSearch(this);">✕</span><span class="results-search"><span class="find">'+this.find+'</span> → <span class="replace">'+this.replace+'</span></span><span class="results-count">'+this.numberOfReplaces+"</span>";this.htmlNode=e;return e}}var searches=Array();var htmlreplace=function(e,t,n,r){if(r==undefined)r=0;if(!n)n=document.body;var i=n.childNodes;for(var s=0;s<i.length;s++){if(i[s].id=="searchAndReplace")continue;if(i[s].nodeType==Node.TEXT_NODE){if(i[s].parentNode.tagName.toLowerCase()!="script"&&i[s].parentNode.tagName.toLowerCase()!="style"){var o=new RegExp("\\b"+e+"\\b","gi");if(i[s].textContent.match(o)){r+=i[s].textContent.match(o).length}i[s].textContent=i[s].textContent.replace(o,t)}}else{r=htmlreplace(e,t,i[s],r)}}return r};var runIt=function(){var e=document.getElementById("__searchAndReplaceForm_Search").value;var t=document.getElementById("__searchAndReplaceForm_Replace").value;var n=htmlreplace(e,t);var r=new Search(e,t,n);searches[searches.length]=r;document.getElementById("start-search-results").parentNode.appendChild(r.createNode())};var removeSearch=function(e){var t=e.parentNode;var n=t.getElementsByTagName("span");var r="";var i="";for(var s in n){var o=n[s];if(o.className=="find")r=o.innerText;if(o.className=="replace")i=o.innerText}for(var u=searches.length-1;u>=0;u--){var a=searches[u];if(a.find==r&&a.replace==i){a.htmlNode.parentNode.removeChild(a.htmlNode);htmlreplace(i,r);searches.splice(u,1)}}};var stylesNode=document.createElement("style");stylesNode.innerHTML='#searchAndReplace { font-family: Helvetica, sans-serif; position: fixed; bottom: 0px; left: 0px; z-index: 99999999999; width: 100%; min-height: 34px; background-color: rgba(36, 32, 111, .7); border-top: 1px solid black; padding: 10px; text-align: left; } #searchAndReplace > form > ul > li > input[type="text"] { width: initial; height: initial; padding: 0px 0px 0px 10px; margin: 0px 10px 11px 0px; border: 3px solid rgba(255,255,255,1); border-radius: 17px; line-height: 26px; font-size: 18px; } #searchAndReplace > form > ul > li > input[type="submit"] { background-color: rgba(0, 0, 0, .5); color: white; font-size: 18px; line-height: 26px; width: 165px; border: 4px solid rgba(255, 255, 255, 1); border-radius: 20px; margin: 0px; padding: 0px; } #searches { list-style-type: none; padding: 0px; margin: 0px; margin-top: 10px; display: inline-block; } #searches > li { display: inline-block; } #searches > li.search-result { display: inline-block; color: white; background-color: #5049BC; border: 1px solid white; border-radius: 25px; padding-left: 4px; padding-right: 4px; padding-top: 3px; padding-bottom: 3px; margin-bottom: 10px; margin-right: 5px; } #start-search-results > span { display: inline-block; width: 1px; height: 30px; line-height: 30px; position: static; top: 13px; color: white; margin-left: 20px; margin-right: 20px; background-color: white; } .results-count { display: inline-block; text-align: center; font-size: 14px; line-height: 16px; color: white; background-color: #40406F; border-radius: 10px; width: 18px; height: 17px; padding-top: 1px; padding-right: 7px; padding-left: 8px; margin-left: 8px; } .results-remove { font-size: 14px; line-height: 16px; display: inline-block; position: relative; border-radius: 10px; width: 18px; color: white; text-align: center; height: 17px; margin-right: 8px; padding-top: 1px; } .results-remove:hover { background-color: #40406F; } .results-search { display: inline-block; text-align: center; font-size: 14px; line-height: 16px; color: white; height: 17px; padding-top: 1px; padding-right: 7px; }';var formNode=document.createElement("div");formNode.id="searchAndReplace";formNode.innerHTML="<form onsubmit='return false;'><ul id='searches'><li><input type='text' placeholder='Find' id='__searchAndReplaceForm_Search'/></li><li><input type='text' placeholder='Replace' id='__searchAndReplaceForm_Replace'/></li><li><input type='submit' value='Find & Replace' onclick='runIt()'/></li><li id='start-search-results'><span> </span></li></ul></form>";if(document.getElementById("searchAndReplace")==null){document.body.appendChild(stylesNode);document.body.appendChild(formNode)}var f=function(){document.body.style.marginBottom="75px"};f()}