var fc_uname; // The passed name var fc_head = document.getElementsByTagName('head')[0]; if ( ! window.jQuery ) { // If jQuery has not been included on the page yet, // we need to include it so we can easily use JSONP. var jquery = document.createElement('script'); jquery.setAttribute('type', 'text/javascript'); jquery.setAttribute('async'); jquery.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'); jquery.onload = execute; fc_head.appendChild(jquery); // Load jQuery, and execute the script when its // loaded. } else { // jQuery has already been loaded, execute the script. execute(); } // Function to actually execute the script. function execute() { fc_uname = getParameterByName('name'); // Get the name if ( fc_uname.length > 0 ) { // If the name is passed var fc_style = document.createElement('link'); fc_style.setAttribute('rel', 'stylesheet'); fc_style.setAttribute('href', 'http://www.themesltd.com/follower-counter/counter-text.css'); fc_style.setAttribute('media', 'screen'); fc_style.onload = function() { document.getElementById('fc_counter_anchor').style.display = 'block'; } fc_head.appendChild(fc_style); // Load the counter CSS in, and show the anchor when its loaded. var fc_script = document.createElement('script'); fc_script.setAttribute('type', 'text/javascript'); fc_script.setAttribute('src', 'http://www.themesltd.com/follower-counter/counter_code.php'); fc_script.setAttribute('id', 'script_fc_code'); var fc_script_id = document.getElementById('script_fc_code'); if(fc_script_id){ fc_head.removeChild(fc_script_id); } fc_head.appendChild(fc_script); // Insert the code JS var anchor = $(''); //anchor.attr('style', 'display:none;'); anchor.addClass('follower-count-button-text'); anchor.attr('href', 'http://www.themesltd.com/follower-counter/stats.php?name='+fc_uname); anchor.attr('target', '_blank'); anchor.attr('title', 'Follower Counter by ThemesLtd'); anchor.attr('id', 'fc_counter_anchor'); anchor.html('Loading'); $('body').append( anchor ); if ( typeof(followerOffsetTop) !== "undefined" ) { document.getElementById('fc_counter_anchor').style.top = followerOffsetTop + 'px'; } // Set the top offset if supplied } } function show_fc_counter(fc_code) { var fc_counter_anchor = document.getElementById('fc_counter_anchor'); // Get the anchor $.ajax({ url: 'http://www.themesltd.com/follower-counter/counter.php?name='+fc_uname+'&code='+fc_code+'&output=jsonp', dataType: 'jsonp', success: function( data ) { if ( typeof(followertext ) !== "undefined" ) { fc_counter_anchor.innerHTML = data + ' '+followertext; }else{ fc_counter_anchor.innerHTML = data + ' Followers'; } // Set the text } }); } function getParameterByName(fc_name) { var fc_script_location = getScriptQuery('folcounter-text.js'); fc_name = fc_name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var fc_regexS = "[\\?&]" + fc_name + "=([^&#]*)"; var fc_regex = new RegExp(fc_regexS); var fc_results = fc_regex.exec(fc_script_location); if(fc_results == null) return ""; else return decodeURIComponent(fc_results[1].replace(/\+/g, " ")); } function getScriptQuery(fc_identifier) { var fc_scripts = document.getElementsByTagName('script'), fc_i, fc_curScript; for (fc_i = 0; fc_i < fc_scripts.length; ++fc_i) { fc_curScript = fc_scripts[fc_i]; if (fc_curScript.src.match(fc_identifier)) { return (fc_curScript.src.match(/\?.*/) || [undefined])[0]; } } }