VinSolutions DealerSites Tool
// ==UserScript==
// @name VinSolutions DealerSites Tool
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://*/*
// @copyright 2012+, You
// ==/UserScript==
// ==UserScript==
// @name DealerSitesInfo2
// @namespace VinSolutions
// @description Displays information about dealersites. Version 2.2
// @include *
// @version 2.4
// ==/UserScript==
// [Next up]
// Add everything in in markup (e.g. [Theme Dir], [Website Dir], etc) and then display through styles and jQuery and assign attributes
// Stop SAVED custom content pages from load MotoSnap in parent window
// [Problems]
// On sites where their style sheets are in their dealersites directory - missing a slash at beginning
// (e.g. http://mykcford.com/ )
function get_meta(name){
var m = document.getElementsByTagName('meta');
for(var i in m) {
if(m[i].name == name){
return m[i].content;
}
}
return "";
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
var dsi = get_meta("VinSolutionsSupportInfo");
if(dsi != ""){
var clean = dsi.replace(/\|/g,',');
var info = eval("({" + clean.trim() + "})");
//create stylesheet
var cssInsert = document.createElement('style');
var cssStyle = "span.dsdum2, span.csstheme { cursor:pointer;} #showdsdbox, #dsdbox { -webkit-transition:all 0.3s ease-out; -moz-transition:all 0.3s ease-out; transition:all 0.3s ease-out;} #dsdcontainer{font-family:AppleGothic,Arial,sans; font-size:11px; color:#fff; position:fixed; top:10px; left:10px; background:none transparent; height:auto; width:auto; z-index:9999;} #showdsdbox{display:block; width:16px; height:16px; background:none transparent; border-radius:16px; cursor:pointer; opacity:.5; padding:10px;} #showdsdbox.showdsdbox{background-color:rgba(75,75,75,.8); border-radius:16px 16px 0 0; opacity:1;} #showdsdbox:hover{opacity:1; box-shadow:0 0 5px rgba(0,0,0,.75);} #showdsdbox.showdsdbox:hover{box-shadow:none;} #showdsdbox:hover #dsdbox{display:block;} #showdsdbox:hover #dsdinfo{display:block;color:white;} #dsdbox{padding:.8em; background-color:rgba(75,75,75,.8); border-radius:0 8px 8px 8px; position:absolute; top:36;} #dsdinfo{font-size:.8em;} #dsdinfo .dsdnum3{display:inline-block; padding:.5em .5em; margin:0 0 .5em .5em; background:firebrick; border-radius:3px; box-shadow:1px 1px 1px rgba(0,0,0,.8);} #dsdinfo .dsdnum span{ font-size:1.6em; font-weight:bold; padding-right:10px; color:white !important;} #dsdhiddenlist { max-height:200px; overflow: auto; } #dsdlist, #dsdhiddenlist {min-width:240px; padding:0; margin:0; list-style:none outside none; display:block; margin:.5em 0 0; padding:.5em 20px 0 0; border-top:dotted 1px rgba(255,255,255,.8);} #dsdlist li, #dsdhiddenlist li{margin:2px auto;} #dsdlist a,#dsdlist a:link,#dsdlist a:visited, #dsdhiddenlist a,#dsdhiddenlist a:link,#dsdhiddenlist a:visited{display:inline-block; font-size:1em; line-height:1em; padding:3px 5px; border-radius:3px; text-decoration:none; color:#fff;} #dsdinfo span.csstheme.hover, #dsdlist a:hover, #dsdlist a.hover, #dsdlist a:focus, #dsdhiddenlist a:hover, #dsdhiddenlist a.hover, #dsdhiddenlist a:focus, #dsdhiddenlist a.focus{color:#fff; background-color:rgba(255,255,255,.5);} #dsdbox:hover, #dsdbox.hover{box-shadow:4px 4px 4px rgba(0,0,0,.8);} #dsdcontainer:hover #dsdbox, #dsdcontainer:hover #showdsdbox.showdsdbox{background-color:rgba(0,75,200,1);} #dsdbox a:hover, #dsdbox a.hover, #dsdbox a:focus { cursor: pointer; background-color: rgba(255, 255, 255, 0.5); color: #FFFFFF; } #dsdbox a, #dsdbox a:link, #dsdbox a:visited { border-radius: 3px 3px 3px 3px; color: #FFFFFF; display: inline-block; font-size: 1em; line-height: 1em; padding: 3px 5px; text-decoration: none; } #showhidedomains:hover, #showhidedomains:focus, #dsdinfo span.csstheme.hover { cursor: pointer; background-color: rgba(255, 255, 255, 0.5); color: #FFFFFF; } #showhidedomains:link, #showhidedomains, #dsdinfo span.csstheme { border-radius: 3px 3px 3px 3px; color: #FFFFFF; display: inline-block; font-size: 1em; line-height: 1em; padding: 3px 5px; text-decoration: none; }";
cssInsert.setAttribute('type','text/css');
cssInsert.innerHTML = cssStyle;
//create script
var scriptInsert = document.createElement('script');
// Cookie handling functions (setCookie, getCookie, deleteCookie)
var scriptContent = "function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = \"; expires=\"+date.toGMTString(); } else var expires = \"\"; document.cookie = name+\"=\"+value+expires+\"; path=/\";} function getCookie(name) { var nameEQ = name + \"=\"; var ca = document.cookie.split(\';\'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==\' \') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function deleteCookie(name) { setCookie(name,\"\",-1); }";
// Functions to toggle the display of hidden domains
scriptContent += "function hideDomain(domainname) { setCookie(\'hide-\'+domainname,\'1\',7000); $(\'#dsdlist li a[href*=\"\'+domainname+\'\"]:contains(\"[hide]\")\').attr(\'href\',$(\'#dsdlist li a[href*=\"\'+domainname+\'\"]:contains(\"[hide]\")\').attr(\'href\').replace(\'hideDomain\',\'showDomain\')).text(\'[show]\'); $(\'#dsdlist li a[href*=\"\'+domainname+\'\"]\').parent().parent().appendTo(\'#dsdhiddenlist\'); if ($(\'#dsdhiddenlist span\').length) { $(\'#showhidedomains\').show(); } else { $(\'#showhidedomains\').hide(); } } function showDomain(domainname) { deleteCookie(\'hide-\'+domainname); $(\'#dsdhiddenlist li a[href*=\"\'+domainname+\'\"]:contains(\"[show]\")\').attr(\'href\',$(\'#dsdhiddenlist li a[href*=\"\'+domainname+\'\"]:contains(\"[show]\")\').attr(\'href\').replace(\'showDomain\',\'hideDomain\')).text(\'[hide]\'); $(\'#dsdhiddenlist li a[href*=\"\'+domainname+\'\"]\').parent().parent().appendTo(\'#dsdlist\'); if ($(\'#dsdhiddenlist span\').length) { $(\'#showhidedomains\').show(); } else { $(\'#showhidedomains\').hide(); } } $(\'#dsdbox\').append(\'<span id=\"showhidedomains\" style=\"font-size:9px; display: none; color:yellow; font-weight:bold; float:left;\">[hidden domains]</span>\'); $(\'#showhidedomains\').click(function() { $(\'#dsdhiddenlist\').toggle(); }); $(\'li a.vindomain\').each(function() { if (getCookie(\'hide-\'+ $(this).text())) { hideDomain($(this).text()); } });";
// On Document Ready code - Everything beyond this is executed on document ready state
scriptContent += "$(function() { ";
// Code to load and implement the zClip jQuery library - which allows to user to click to copy to clipboard
scriptContent += "$.getScript(\"http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/jquery.zclip.js\", function() { $('#dsdinfo span.dsdnum span.dsdum2').each(function() { $(this).zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$(this).text().trim(), afterCopy:function() {} }); }); $('#dsdinfo a.cssfile').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdinfo a.cssfile').attr('file'), afterCopy:function() {} }); $('#dsdinfo a.themedir').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdinfo a.themedir').attr('file'), afterCopy:function() {} }); $('#dsdinfo a.websitedir').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdinfo a.websitedir').attr('file'), afterCopy:function() {} }); $('#dsdinfo a.dsedgefile').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdinfo a.dsedgefile').attr('file'), afterCopy:function() {} }); $('#dsdinfo span.csstheme').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdinfo span.csstheme').text().trim(), afterCopy:function() {} }); $('#dsdbox a.menufile').zclip({path:'http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/copy-clipboard\/ZeroClipboard.swf', copy:$('#dsdbox a.menufile').attr('file'), afterCopy:function() {} }); });";
// Code to load website editing functionality
scriptContent += "/*$.getScript(\"http:\/\/ballwegchevrolet.vinwebsitestage.com\/dealersites\/Themes\/CommonScripts\/editwebsite.js\", function() { console.log(\"loaded\"); });*/";
// Code to implement [NOCACHE] button
scriptContent += "$('#nocachebtn').click(function() { var nocache = ''; var nocacheURL = ''; if (window.location.search.indexOf('NOCACHE') == -1) { if (window.location.search.indexOf('?') == 0) { nocache = '&NOCACHE=' + Math.floor((Math.random() * 100000)) + 'p'; } else { nocache = '?NOCACHE=' + Math.floor((Math.random() * 100000)) + 'p'; } nocacheURL = window.location.href + nocache; } else { nocacheURL = window.location.href.replace(/NOCACHE=[0-9]+p/gi, ('NOCACHE=' + Math.floor((Math.random() * 100000)) + 'p')); } window.location.href = nocacheURL; });";
// Code for [Theme Dir], [DSEdge], [Website Dir], and [CSS File] buttons
scriptContent += "var rawCSSFile = $('head link[href*=\"styles.css\"]').attr('href'); var CSSFile = rawCSSFile.toLowerCase().replace('http://dsedge.vinsolutions.com/','').replace('/dealersites','\\\\\\\\DEALERSITEDEV\\\\DealerSites_Content').replace('dealersites','\\\\\\\\DEALERSITEDEV\\\\DealerSites_Content').replace(/\\\//g, '\\\\'); var styleSheet = rawCSSFile.replace(/\\/dealersites\\/themes\\//i,'').replace(/dealersites\\/themes\\//i,'').replace(/CSS\\/styles.css/i,'').replace('http://dsedge.vinsolutions.com','<a class=\"dsedgefile\" target=\"_blank\" style=\"color:yellow;\" file=\"'+$('head link[href*=\"styles.css\"]').attr('href')+'\">[DSEdge]</a> '); $(\'#dsdinfo div:first\').append('<br /><span style=\"font-size:9px; margin-top:5px; display:block; padding-right:10px; color: yellow; font-weight:bold;\" class=\"nodrag\">Stylesheet: <span title=\"Click to copy to clipboard\" class=\"csstheme\">'+styleSheet+'</span> <a class=\"cssfile\" target=\"_blank\" style=\"color:yellow;\" file=\"'+CSSFile+'\">[CSS File]</a></span>'); $('div#dsdinfo span.csstheme a').insertAfter($('#dsdinfo div:first span:last')); var themeDir = CSSFile.replace('http://dsedge.vinsolutions.com','').replace(/CSS\\\\styles.css/i,''); var websiteDir = \"\\\\\\\\DEALERSITEDEV\\\\DealerSites_Content\\\\"+ info.WebsiteID+"\\\\\"; $(\'#dsdinfo div:first span:last\').after('<br /><a class=\"websitedir\" target=\"_blank\" style=\"color:yellow;\" file=\"'+websiteDir+'\">[Website Dir]</a> <a class=\"themedir\" target=\"_blank\" style=\"color:yellow;\" file=\"'+themeDir+'\">[Theme Dir]</a>');";
// Code to determine whether Menu Builder is being used or not / [File] button
scriptContent += "if ($(\'ul.pNav li.menuItem a[title]\').length) { $(\'#dsdinfo .dsdnum:last\').before(\'<span style=\"font-size:9px; color:white; font-weight:bold; display:block;\">Using Menu Builder</span>\');} else { var menuFile = \"\\\\\\\\DEALERSITEDEV\\\\DealerSites_Content\\\\"+ info.WebsiteID+"\\\\menu.xml\"; $(\'#dsdinfo .dsdnum:last\').before('<span style=\"font-size:9px; color:white; font-weight:bold; display:block;\">Not Using Menu Builder <a class=\"menufile\" target=\"_blank\" style=\"color:yellow;\" file=\"'+ menuFile +'\">[File]</a></span>\');}";
// Code to fix the original website edit mode / Make dsdcontainer not draggable
scriptContent += "$(\'.hilite\').find(\'span\').attr(\'id\',\'customcontent_metadata\'); $( \"#dsdcontainer\" ).draggable({ cancel: \".nodrag\" });";
// Code to toggle the display of [Custom Content] page links and to build those links
scriptContent += "if ($(\'#content div.customcontent span:contains(\"|"+ info.WebsiteID +"\")\').length) { $(\'#openinmotosnap\').after(\'<a class=\"customcontentshowhide\" style=\"margin-right:2px; color:white;\" target=\"_blank\">[Custom Content]</a>\'); $('.customcontentshowhide').click(function() { $('.customcontentlink').toggle(); }); $(\'#content div.customcontent span:contains(\"|"+ info.WebsiteID +"\")\').each(function() { var tempStr2 = $(this).attr(\'id\'); if (tempStr2 == undefined) { var tempStr2 = $('body').attr('class'); var tempStr3 = tempStr2; } else { var tempStr3 = tempStr2.substring(tempStr2.indexOf(\'ContentSection_\')+15,tempStr2.indexOf(\'_customcontent\')); } var metad = $(this).text(); if (tempStr2.match(\'GetQuote\')) { } else { var tempStr = $(this).text(); var customContentPageNumber = tempStr.substring(0, tempStr.indexOf(\'|\')); $(\'#nocachebtn\').after(\'<a metad=\"'+ metad +'\" class=\"customcontentlink\" style=\"margin-right:2px; color:white;\" target=\"_blank\" href=\"http://apps.vinmanager.com/CarDashboard/Pages/Website/EditPage.aspx?ID=\' + customContentPageNumber + \'&websiteid="+ info.WebsiteID +"&NoFrame=0\">[Custom Content - '+ tempStr3 +']</a>\'); } }); $('.customcontentlink').hide(); }";
// End of Document Ready
scriptContent += "});";
// Misc
scriptContent += "function showBox(){var div = document.getElementById(\"dsdbox\"); div.setAttribute(\"style\",\"display:block;\"); var btn = document.getElementById(\"showdsdbox\"); btn.setAttribute(\"onClick\",\"hideBox()\"); var act = document.getElementById(\"showdsdbox\"); act.setAttribute(\"class\",\"showdsdbox\");} function hideBox(){ var div = document.getElementById(\"dsdbox\"); div.setAttribute(\"style\",\"display:none;\"); var btn = document.getElementById(\"showdsdbox\"); btn.setAttribute(\"onClick\",\"showBox()\"); var act = document.getElementById(\"showdsdbox\"); act.setAttribute(\"class\",\"\"); } function showDomains(){ var ul = document.getElementById(\"dsd334235235423\"); ul.setAttribute(\"style\",\"padding:10px;\"); var a = document.getElementById(\"showdsd334235235423\"); a.innerHTML = \"hide\"; a.setAttribute(\"onclick\",\"hideDomains()\"); } function hideDomains(){ var ul = document.getElementById(\"dsd334235235423\"); ul.setAttribute(\"style\",\"padding:10px; display:none;\"); var a = document.getElementById(\"showdsd334235235423\"); a.innerHTML = \"show\"; a.setAttribute(\"onclick\",\"showDomains()\"); }";
scriptInsert.setAttribute('type','text/javascript');
scriptInsert.innerHTML = scriptContent;
//markup
var dsdContainer = document.createElement('div');
dsdContainer.setAttribute('id','dsdcontainer');
var markupHTML = "<a onclick=\"hideBox()\" id=\"showdsdbox\" class=\"showdsdbox\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACsklEQVR42m2TS0xTQRSGz8q9xsToqokLFywNCzcQNbKxGKy6EOQRNYFojC4QannZBkppg1BFlJeAFlrowxIfhFLAKwE0xCjl1XtbkfKIBrReRSQm2N8ZSAM2fMmfe5I5X2Yy9wwFghIFgwEKbCXJ6JIqC62BERaZp4DVpQ6pkq8FAtJWL6u3i4oyu2QusgXXtJ0zKHfNQmufgcE1h5Z+Gc1936Gzf1orsolm3hvdlKSAxKMobBc9Oia0CasYmv6DWNyji2jyhmHqWoDaInq4w10SJZF0dtFZ6gzBMbyGnVBqWkHx11DfP42G3mXo2AmLraKTuzQ57c8stErr9qFN+VCaEXRMA0rWIb/JCw6lmkGqCsSnG8Gp7w1D0y6te9+KmWR+NiPUecLQd0lQ173AwZyHSK7uBqXXbCbrPkJff0JV9RxRJkJg9zELkzskUF6bX3aM/kXXSBA7QRdqWO4hFqN7HlkPRmVSGgYiFU/nEIu2YwjHS2wY8i9iV3Y9KO0uKJVFqUXcxWrsu9GG6y2TETqi6YoklLz8f9ezJpDKCDrNckqPKJRRA0rIRWJuM9S2IJo84QhVuBdkOncH7mE/XIOToDOmDXHvpVqcuN3B6grsyTAjFsvACm5Z/DK53qwISn0faPdJ0OEroEQ1FpZkRKHzVaAUA7YzPPWbzYIf2k5JoA++8cyGvh/rKabXOKq1IxZVuQOkLMV28i0iCthv7BmeyqSJyQkyuILOJ4OraH0lI5ayxm5Q3GVEKbZ95DPAvpKTuzQ+Mc6jKLBKnhI2YXo2kRbhM6JMzX8DJdzEaHAFtT3LyNvc3cMd7pJv3BeNQtfpN7PFNfb6+AWhVfiFq41jOJDTgses5mvFVsnMe6MejfnGYpOkd4gbz7mme0lWmQR5f/ajkUbvl8p378eSYvv/AVeW8rYJ1UYDAAAAAElFTkSuQmCC\" /></a><div id=\"dsdbox\" style=\"display:block;\"><div id=\"dsdinfo\"><div>";
var domains = "<ul id=\"dsdlist\" class=\"nodrag\">";
var metadomains = info.Domains.split(',');
for (domain in metadomains) {
domains += "<span><li><a class=\"vindomain\" href=\"http://"+ metadomains[domain] +"/\">"+ metadomains[domain] +"</a></li>";
domains += "<li style=\"margin-top:-5px; padding-bottom:5px;\"><a href=\"http://"+ metadomains[domain] + window.location.pathname +"\">[current path] </a><a href=\"http://"+ metadomains[domain] +"/mobile/touch/\">[mobile site]</a> <a href=\"javascript:hideDomain('"+ metadomains[domain] +"');\">[hide]</a></li></span>";
}
domains += "</ul>";
domains += "<ul id=\"dsdhiddenlist\" style=\"display:none;\" class=\"nodrag\">";
domains += "</ul>";
markupHTML += "<span class=\"dsdnum\" style='color:white;'>pdID:<span title=\"Click to copy to clipboard\" class=\"dsdum2 nodrag\">" + info.PrimaryDealerID + "</span></span> <span class=\"dsdnum dsdnum3\" style='color:white;'>wID:<span title=\"Click to copy to clipboard\" class=\"dsdum2 nodrag\">" + info.WebsiteID + "</span></span></div><span class=\"dsdnum\" style='color:white;'>Server: " + info.Server + "<br /><a id=\"openinmotosnap\" style=\"color:white; margin-right:5px;\" target=\"_blank\" href=\"https://apps.vinmanager.com/CarDashboard/Pages/Website/EditWebSite.aspx?SelectedTab=t_Admin&NoFrame=0&From=Admin&WebSiteID="+ info.WebsiteID +"\">[MotoSnap]</a> <a id=\"nocachebtn\" style=\"font-weight: normal; font-size: 1em; cursor: pointer;\" >[NOCACHE]</a></span></div>" + domains + "</div>";
//... and post it for the world to see.
document.body.appendChild(dsdContainer);
dsdContainer.innerHTML = markupHTML;
dsdContainer.appendChild(cssInsert);
dsdContainer.appendChild(scriptInsert);
}