Last active
December 17, 2015 18:19
-
-
Save sujeet/5652911 to your computer and use it in GitHub Desktop.
UserScript to add Facebook like count in Blogger Dashboard.
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 Facebook Likes in Blogger Dashboard | |
| // @author Sujeet Gholap | |
| // @description This userscript adds another column for Facebook likes on Blogger dashboard. | |
| // @match http://*.blogger.com/blogger.g* | |
| // @match https://*.blogger.com/blogger.g* | |
| // ==/UserScript== | |
| function main () { | |
| (function() { | |
| // Load the script | |
| function log_like_count (link, row) | |
| { | |
| function add_like_info (data) | |
| { | |
| // Add only if not already added. | |
| if (row.children.length > 8) return; | |
| var likes_count = 0; | |
| var fb_sprite_url = "'https://fbstatic-a.akamaihd.net/rsrc.php/v2/yg/r/Qdv04UHuWZa.png'"; | |
| var like_icon = '<i class="pluginButtonIcon img sp_like sx_like_thumb"' | |
| + ' style="background-image: url('+fb_sprite_url+');' | |
| + ' background-position: 0 -35px;' | |
| + ' width: 15px;' | |
| + ' height: 15px;' | |
| + ' display: block;' | |
| + ' float: left;' | |
| + ' margin-right: 5px;">' | |
| + '</i>'; | |
| if (data[0]) { | |
| likes_count = data [0].total_count; | |
| } | |
| jQ(row.children[7]).after( | |
| '<td class="GIL3GQOBEO GIL3GQOBCO fb-like-count"' | |
| + ' valign="top"' | |
| + ' align="left"' | |
| + ' style="min-width:45px;">' | |
| + like_icon + likes_count | |
| + '</td>' | |
| ); | |
| }; | |
| jQ.ajax( | |
| { | |
| url:"https://api.facebook.com/method/fql.query?" | |
| + "query=select total_count from link_stat where url='"+link+"'" | |
| + "&format=json", | |
| context: document.body | |
| } | |
| ).done(add_like_info); | |
| }; | |
| var my_tables = jQ('.bloggPostTable'); | |
| for (var j = 0; j < my_tables.length; j++) { | |
| var my_table = my_tables [j]; | |
| my_table.style.tableLayout = "auto"; | |
| for (var i = 0; i < my_table.rows.length - 1; i++) { | |
| log_like_count(my_table.rows[i].getElementsByClassName('blogg-visible-on-select')[0].children[1].href, | |
| my_table.rows[i]); | |
| } | |
| } | |
| console.log ('attempting...'); | |
| // Last requests were unsuccessful. Attempt again. | |
| if (jQ (".fb-like-count").length == 0) window.setTimeout (arguments.callee, 1000); | |
| })(); | |
| } | |
| function addJQuery(callback) { | |
| var script = document.createElement("script"); | |
| script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"); | |
| script.addEventListener('load', function() { | |
| var script = document.createElement("script"); | |
| script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
| document.body.appendChild(script); | |
| }, false); | |
| document.body.appendChild(script); | |
| } | |
| addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment