// ==UserScript== // @name Better Tripadvisor // @description Precise ratings, no restaurant ads, website link, phone number, google search link // @namespace KrisWebDev // @author KrisWebDev // @include http://www.tripadvisor.tld/* // @include https://www.tripadvisor.tld/* // @version 2020.08 // @grant GM_xmlhttpRequest // @grant GM_addStyle // @require http://code.jquery.com/jquery-2.1.4.min.js // @icon https://static.tacdn.com/favicon.ico // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); GM_addStyle('.ui_icon.google::before { content: "\u2315"; }'); // Restaurants: Remove adds GM_addStyle('div[data-test="SL_list_item"] { display: none; }'); /* PRECISE RATINGS */ var coeff = 5; var result = 0; var sumReviews = 0; var percentReviews = 0; var stop = 0; // Hotels $("label[for^='ReviewRatingFilter_']").parent("li").each(function(index,val) { var irating = $(this).children("span").last().text(); console.log(irating); percentReviews = parseInt(irating.replace(/\s+/g, '')); result += percentReviews*coeff--; sumReviews += percentReviews; }); if (sumReviews) { result = (Math.round(result/sumReviews*10))/10; // console.log("Result="+result); $("span[class*='__overallRating']").css("display","hide"); $("div#ABOUT_TAB").parent().parent().before($("
").attr( "style", "font-size: 48px;line-height: 22px;font-weight: 700;color: #078171; padding-bottom: 20px").text(result.toFixed(1))); } // Attractions if (!sumReviews) { stop=0; $(".row_count").each(function(index, val) { if(stop++ == 5) return false; percentReviews = parseInt($(this).text().replace(/[^0-9]/g, '')); result += percentReviews*coeff--; sumReviews += percentReviews; stop++; }); if (sumReviews) { // console.log(sumReviews); result = (Math.round(result/sumReviews*10))/10; console.log("Result="+result); $("span[class*='__overallRating']").css("display","hide"); $("div#btf_wrap").prepend($("
").attr( "style", "font-size: 48px;line-height: 22px;font-weight: 700;color: #078171; padding-top: 20px").text(result.toFixed(1))); } } // Attraction Reviews if (!sumReviews) { stop=0; $(".row_num.is-shown-at-tablet").each(function(index, val) { if(stop++ == 5) return false; percentReviews = parseInt($(this).text().replace(/[^0-9]/g, '')); result += percentReviews*coeff--; sumReviews += percentReviews; stop++; }); if (sumReviews) { result = (Math.round(result/sumReviews*10))/10; // console.log("Result="+result); $("span[class*='__overallRating']").css("display","hide"); $("div#REVIEWS").parent().prepend($("
").attr( "style", "font-size: 48px;line-height: 22px;font-weight: 700;color: #078171; padding-bottom: 20px").text(result.toFixed(1))); } } if (sumReviews) { result = (Math.round(result/sumReviews*10))/10; // console.log("Result="+result); $("span[class*='__overallRating']").css("display","hide"); $("div#ABOUT_TAB").parent().parent().before($("
").attr( "style", "font-size: 48px;line-height: 22px;font-weight: 700;color: #078171; padding-bottom: 20px").text(result.toFixed(1))); } /* LEFT/RIGHT KEYS TO SLIDE PHOTOS */ /* $(document).keyup(function(e) { switch (e.key) { case "ArrowRight": $("div.navigationItem.single-chevron-right").click(); break; case "ArrowLeft": $("div.navigationItem.single-chevron-left").click(); break; } }); */ /* HELPER FUNCTIONS */ function getHTTP(queryURL, handlerPassArg, handler) { var http; GM_xmlhttpRequest({ method: "GET", url: queryURL, timeout: 15000, headers: { Referer: document.URL }, onreadystatechange: function(http) { if (http.readyState == 4) { if(http.status == 200) { handler(http.responseText, handlerPassArg, queryURL); } http = null; } } }); } /* WEBSITE LINK, PHONE HANDLER */ function appendGeneralInfo(response, jContainer, queryurl) { var websiteURL = null; var phoneNum = null; var genInfoHTML = ""; if(needPhone) if(phoneNum=response.match(/data-attr="phone"\s*value="([0-9 \+\(\)]+)"/)) genInfoHTML+=''; if(needWebsite) if(websiteURL=response.match(/data-attr="website"\s*value="(https?:\/\/[^"]+)"/)) genInfoHTML+=''; if (genInfoHTML) jContainer.append(genInfoHTML); } /* LAUNCHERS */ var jBlRow=$("div.headerBL > .blRow"); if (jBlRow.length) { /* GOOGLE SEARCH LINK */ var jHeader=$("h1#HEADING"); if(jHeader.length) { var googleSearchHTML = ""; googleSearchHTML+=''; jBlRow.append(googleSearchHTML); } /* WEBSITE LINK, PHONE LAUNCHER */ var jUpdateListingAnchor=$("a[href^='/UpdateListing-']"); var blEntryPhone=$(".blEntry.phone"); var blEntryWebsite=$(".blEntry.website"); var needPhone=!blEntryPhone.length;// && !$blEntryPhone.find("a[href^='/UpdateListing-']").length; var needWebsite=!blEntryWebsite.length;// && !blEntryWebsite.find("a[href^='/UpdateListing-']").length; // console.log(needWebsite); if (jUpdateListingAnchor.length && (needPhone || needWebsite)) getHTTP(jUpdateListingAnchor[0].href, jBlRow, appendGeneralInfo); }