Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Chaturbate Optimizer
- // @description Optimize chaturbate.com, Find models by country and age.
- // @include http*://*.chaturbate.com/*
- // @include http*://chaturbate.com/*
- // @exclude http*://*.chaturbate.com/followed-cams/
- // @exclude http*://chaturbate.com/followed-cams
- // @updateURL https://searchnmore.000webhostapp.com/cb-findagirl.user.js
- // @downloadURL https://searchnmore.000webhostapp.com/cb-findagirl.user.js
- // @grant GM_xmlhttpRequest
- // @grant GM_addStyle
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_log
- // @version 2.9
- // ==/UserScript==
- document.optimizerVersion = "2.9";
- //changelog
- //Dug out old script from somewhere, fixd it up.
- //added filter by country
- // =============================================================================
- // === Global settings =========================================================
- // =============================================================================
- // Additional helper functions
- String.prototype.endsWith = function (pSuffix) {
- return this.indexOf(pSuffix, this.length - pSuffix.length) !== -1;
- };
- // =============================================================================
- // === CSS Styles ==============================================================
- // =============================================================================
- // Overwrite existing styles to make the elements displayed look better and
- // nicer
- GM_addStyle("#botright { display: none !important; }");
- //GM_addStyle("#defchat { width: 1000px !important; }");
- // Define internal CSS classes for easier access
- GM_addStyle(".marvinateButton { font-weight: bold; background-color: #E9E9E9; padding: 6px 8px 4px 8px; margin: 0px 4px 0px 0px; color: #006B94; border: 1px solid #006B94; }");
- GM_addStyle(".marvinateButtonActive { background-color: #FFFFFF; }");
- GM_addStyle(".marvinateButton:hover { cursor: pointer; text-decoration: none; background-color: #006B94; color: white; } ");
- GM_addStyle(".marvinateButtonSmall { display: inline-block; font-weight: bold; background-color: #E9E9E9; padding: 4px 8px 4px 8px; margin: -2px 5px -4px 10px; color: #006B94; border: 1px solid #006B94; }");
- GM_addStyle(".marvinateButtonSmall:hover { cursor: pointer; text-decoration: none; background-color: #006B94; color: white; } ");
- GM_addStyle(".marvinateSelf { padding: 5px 8px 5px 8px; line-height: 1; position: absolute; left: 280px; top: 8px; border: 1px solid #006B94; font-family: Verdana, Tahoma, Arial, Helvetica; }");
- GM_addStyle(".marvinateSelf small { font-size: 10px; }");
- GM_addStyle(".marvinateSelfTitle { font-size: 12px; font-weight: bold; color: #000000; }");
- GM_addStyle(".marvinatePrefs { width: 500px; margin: 20px auto 0px auto; padding: 10px 15px 10px 15px; border: 5px solid #006B94; background-color: #E9E9E9; }");
- GM_addStyle(".marvinatePrefsTitle { font-weight: bold; font-size: 15px; margin: 0px 0px 10px 0px; }");
- GM_addStyle(".marvinatePrefsWrapper { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 9999; }");
- GM_addStyle(".marvinatePrefsTable { width: 100%; }");
- GM_addStyle(".marvinatePrefsTable td.title { width: 200px; padding: 1px 2px 1px 0px; }");
- GM_addStyle(".marvinatePrefsTable td.content { padding: 1px 0px 1px 2px; }");
- GM_addStyle(".marvinatePrefsTable td.content input[type=text] { width: 150px; }");
- GM_addStyle(".marvinatePrefsButtons { margin: 10px 0px 0px 0px; }");
- GM_addStyle(".marvinateDetailInfo { display: inline-block; position: absolute; left: 0; top: 0; z-index: 10; }");
- GM_addStyle(".marvinateDetailInfo a { display: block; padding: 8px 4px 8px 4px; font-size: 22px; font-weight: bold; text-decoration: none; border: 1px solid #444444; margin: 5px 0px 0px 5px; }");
- GM_addStyle(".marvinateDetailInfoLoading { background-color: #ffffff; opacity: 0.4; color: #000000; }");
- GM_addStyle(".marvinateDetailInfoEnabled { background-color: #ff9999; opacity: 0.65; color: #000000; }");
- GM_addStyle(".marvinateDetailInfoDisabled { background-color: #99ff99; opacity: 0.4; color: #99ff99; }");
- // =============================================================================
- // === Self identification and header ==========================================
- // =============================================================================
- var logoDiv = MV_getElementByPath("//div[@class='logo-zone']");
- if (logoDiv !== null) {
- var openPreferencesLink = MV_createElement("div", {
- "class": "marvinateButtonSmall"
- }, "Open Preferences");
- openPreferencesLink.addEventListener("click", preferencesOpen, true);
- var titleLink = MV_createElement("div", {
- "class": "marvinateSelfTitle"
- });
- // titleLink.appendChild(document.createTextNode("Optimizations by marvin - Version " + document.optimizerVersion + " "));
- titleLink.appendChild(openPreferencesLink);
- var authorDiv = MV_createElement("div", {
- "class": "marvinateSelf"
- });
- authorDiv.appendChild(titleLink);
- var mycamgirl_completeFunction = function (pElement, pRequest, pResponse) {
- var modelhist = pElement.textContent || pElement.innerText;
- authorDiv.appendChild(MV_createElement("div", {
- "style": "padding: 10px 0px 0px 0px;"
- }, "<small>Last Activity:" + modelhist + "</small>"));
- };
- var mycamgirl_completeFunction2 = function (pElement, pRequest, pResponse) {
- var modelhist = pElement.textContent || pElement.innerText;
- authorDiv.appendChild(MV_createElement("div", {
- "style": "padding: 10px 0px 0px 0px;"
- }, "<small>Total:" + modelhist + "</small>"));
- };
- var errorFunction = function (pRequest, pResponse, pException) {
- };
- var chatpage = MV_getElementByPath("//*[@id=\"defchat\"]/div[2]");
- if (chatpage !== null) {
- var currentPageUrl = window.location.href;
- var lastSlashIndex = currentPageUrl.lastIndexOf("/");
- var currentPageUrl2 = currentPageUrl.substring(0, lastSlashIndex);
- lastSlashIndex = currentPageUrl2.lastIndexOf("/");
- var mycamgirlurl = "http://mycamgirl.net/chaturbate/model" + currentPageUrl.substring(lastSlashIndex);
- authorDiv.appendChild(MV_createElement("div", {
- "style": "padding: 10px 0px 0px 0px;"
- }, "<small>mycamgirl:<a href =\"" + mycamgirlurl + "\">" + mycamgirlurl + "</small>"));
- MV_sendRequest({
- url: mycamgirlurl,
- xpath: "//*[@id=\"act-1\"]",
- onComplete: mycamgirl_completeFunction,
- onError: errorFunction
- });
- MV_sendRequest({
- url: mycamgirlurl,
- xpath: "//*[@id=\"activity-pct\"]",
- onComplete: mycamgirl_completeFunction2,
- onError: errorFunction
- });
- }
- logoDiv.insertBefore(authorDiv, null);
- }
- // =============================================================================
- // === Global :: Utilities =====================================================
- // =============================================================================
- // Replace window.open with a dummy to disable any popups
- unsafeWindow.MV_open = unsafeWindow.open;
- unsafeWindow.open = function (pUrl, pName, pParameters) {
- GM_log("Disabled window.open for URL: " + pUrl);
- };
- // =============================================================================
- // === Global :: Preferences ===================================================
- // =============================================================================
- var country_list = ["russian federation", "London", "united kingdom", "russian", "united states", "europe", "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Anguilla", "Antigua & Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia & Herzegovina", "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Cape Verde", "Cayman Islands", "Chad", "Chile", "China", "Colombia", "Congo", "Cook Islands", "Costa Rica", "Cote D Ivoire", "Croatia", "Cruise Ship", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Estonia", "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", "French West Indies", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kuwait", "Kyrgyz Republic", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Mauritania", "Mauritius", "Mexico", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Namibia", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestine", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", "Saint Pierre & Miquelon", "Samoa", "San Marino", "Satellite", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "South Africa", "South Korea", "Spain", "Sri Lanka", "St Kitts & Nevis", "St Lucia", "St Vincent", "St. Lucia", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor L'Este", "Togo", "Tonga", "Trinidad & Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks & Caicos", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay", "Uzbekistan", "Venezuela", "Vietnam", "Virgin Islands (US)", "Yemen", "Zambia", "Zimbabwe"];
- function preferencesRow(pTitle, pContent) {
- var tableRow = MV_createElement("tr");
- var titleCell = MV_createElement("td", {
- "class": "title"
- }, pTitle);
- var contentCell = MV_createElement("td", {
- "class": "content"
- });
- contentCell.appendChild(pContent);
- tableRow.appendChild(titleCell);
- tableRow.appendChild(contentCell);
- return tableRow;
- }
- function preferencesOpen() {
- var preferencesInnerDiv = MV_createElement("div", {
- "class": "marvinatePrefs"
- });
- var preferencesOuterDiv = MV_createElement("div", {
- "class": "marvinatePrefsWrapper"
- });
- preferencesOuterDiv.close = function () {
- preferencesOuterDiv.parentNode.removeChild(preferencesOuterDiv);
- };
- preferencesOuterDiv.appendChild(preferencesInnerDiv);
- var highlightLanguages = GM_getValue("marvinateHighlightLanguages");
- var highlightLanguagesField = MV_createElement("input", {
- "type": "text",
- "value": highlightLanguages === null ? "" : highlightLanguages
- });
- var hideothersValue = GM_getValue("hideothers") !== false ? true : false;
- var hideothersbox = MV_createElement("input", {"type": "checkbox" });
- if (hideothersValue !== false) hideothersbox.checked = true;
- var ageMinimumValue = GM_getValue("marvinateAgeMinimum");
- var ageMinimumField = MV_createElement("input", {
- "type": "text",
- "value": ageMinimumValue === null ? "" : ageMinimumValue
- });
- var ageMaximumValue = GM_getValue("marvinateAgeMaximum");
- var ageMaximumField = MV_createElement("input", {
- "type": "text",
- "value": ageMaximumValue === null ? "" : ageMaximumValue
- });
- var prefsTable = MV_createElement("table", {
- "class": "marvinatePrefsTable"
- });
- prefsTable.appendChild(preferencesRow("Highlight users from countries", highlightLanguagesField));
- prefsTable.appendChild(preferencesRow("Hide others", hideothersbox));
- prefsTable.appendChild(preferencesRow("Age minimum", ageMinimumField));
- prefsTable.appendChild(preferencesRow("Age maximum", ageMaximumField));
- var saveFunction = function () {
- GM_setValue("marvinateHighlightLanguages", highlightLanguagesField.value);
- GM_setValue("hideothers", hideothersbox.checked !== false ? hideothersbox.value : false);
- GM_setValue("marvinateAgeMinimum", ageMinimumField.value !== null && ageMinimumField.value.length > 1 ? parseInt(ageMinimumField.value.trim()) : "");
- GM_setValue("marvinateAgeMaximum", ageMaximumField.value !== null && ageMaximumField.value.length > 1 ? parseInt(ageMaximumField.value.trim()) : "");
- //alert("Preferences saved! (Reload the current page to make sure they're applied)");
- preferencesOuterDiv.close();
- };
- var prefsButtonArea = MV_createElement("div", {
- "class": "marvinatePrefsButtons"
- });
- prefsButtonArea.appendChild(MV_createButton({
- "class": "marvinateButton",
- "value": "Save Preferences"
- }, saveFunction));
- prefsButtonArea.appendChild(MV_createButton({
- "class": "marvinateButton",
- "value": "Cancel"
- }, function () {
- preferencesOuterDiv.close();
- }));
- preferencesInnerDiv.appendChild(MV_createElement("div", {
- "class": "marvinatePrefsTitle"
- }, ""));
- preferencesInnerDiv.appendChild(prefsTable);
- preferencesInnerDiv.appendChild(prefsButtonArea);
- document.body.appendChild(preferencesOuterDiv);
- }
- // =============================================================================
- // === Cam listings ============================================================
- // =============================================================================
- // Restyle the list element to fit the complete page (normally, on the right
- // side there would be place for ads, but since we removed them all, we can
- // extend the page to fill the remaining space)
- var listElement = MV_getElementByPath("//div[@class='c-1 endless_page_template']");
- if (listElement !== null) {
- listElement.setAttribute("style", "margin: 0px 0px 0px 15px; padding: 0; z-index: 999;");
- }
- // Add the optimizations to be performed dynamically
- var optimizeUserListListeners = [];
- function optimizeUserList() {
- var i = 0;
- while (i < optimizeUserListListeners.length) {
- optimizeUserListListeners[i]();
- i++;
- }
- }
- var refreshThePeopleListRunning = false;
- // Optimize each of the cells in which a user cam is being displayed.
- var profileNodes = document.evaluate("//ul[@class='list']/li", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- if (profileNodes !== null && profileNodes.snapshotLength > 0) {
- // We do not want the site to trigger all timeouts. First of all, no ads
- // should be allowed to be reloaded and second of all, the site implements
- // a global reload scheduling process, that doesn't take the optimizations
- // into account.
- // So, what we do here is to replace the default windows setTimeout function
- // with a dummy, that does nothing. However, if we ourselves ever want to
- // initiate a setTimeout we capture the function itself by making it
- // available under the MV_setTimeout key
- unsafeWindow.MV_setTimeout = unsafeWindow.setTimeout;
- unsafeWindow.setTimeout = function (pFunction) {};
- optimizeUserListListeners.push(function () {
- refreshThePeopleListRunning = true;
- profileNodes = document.evaluate("//ul[@class='list']/li", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- var highlightCountriesPrefsValue = GM_getValue("marvinateHighlightLanguages");
- var highlightCountries = highlightCountriesPrefsValue === null ? null : highlightCountriesPrefsValue.split(",");
- for (var i = 0; i < profileNodes.snapshotLength; i++) {
- var profileNode = profileNodes.snapshotItem(i);
- var alreadyAltered = profileNode.getAttribute("marvinateAltered");
- if (!alreadyAltered) {
- profileNode.setAttribute("marvinateAltered", true);
- // Enhance the list with the information already known from the
- // listings page
- enhanceUserListingElement(profileNode);
- var detailPageUrl = "http://" + window.location.hostname + document.evaluate("a", profileNode, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).getAttribute("href") + "?track=addon28&campaign=gmltV";
- var detailLoadingInfoElement = MV_createElement("div", {
- "class": "marvinateDetailInfo"
- });
- var detailLoadingInfoLink = MV_createElement("a", {
- "class": "marvinateDetailInfoLoading",
- "href": detailPageUrl
- }, "?");
- detailLoadingInfoElement.appendChild(detailLoadingInfoLink);
- document.evaluate("a", profileNode, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).setAttribute("href", detailPageUrl);
- profileNode.appendChild(detailLoadingInfoElement);
- // Now load the detail page and add information only found there
- MV_sendRequest({
- url: detailPageUrl,
- xpath: "//body",
- originalProfileNode: profileNode,
- originalLoadingInfoElement: detailLoadingInfoLink,
- onComplete: function (pElement, pRequest, pResponse) {
- enhanceUserListingElementFromDetailPageInformation(pRequest.originalProfileNode, pElement, pRequest.originalLoadingInfoElement);
- },
- onError: function (pRequest, pResponse, pException) {
- // Ignore here - we canot do anything!
- }
- });
- }
- }
- refreshThePeopleListRunning = false;
- });
- }
- function enhanceUserListingElement(profileNode) {
- profileNode.setAttribute("style", "max-height: 300px");
- var linkElement = MV_getElementByPath("a", profileNode);
- var ageMinimumValue = GM_getValue("marvinateAgeMinimum");
- var ageMinimum = ageMinimumValue === null|| ageMinimumValue == "" ? null : parseInt(ageMinimumValue);
- var ageMaximumValue = GM_getValue("marvinateAgeMaximum");
- var ageMaximum = ageMaximumValue === null || ageMaximumValue == "" ? null : parseInt(ageMaximumValue);
- var ageElement = MV_getElementByPath("div[@class='details']//span[contains(@class, 'age')]", profileNode);
- var ageElementValue = ageElement === null ? null : ageElement.innerHTML;
- var ageInteger = ageElementValue === null|| isNaN(ageElementValue.trim()) ? null : parseInt(ageElementValue.trim());
- if (ageInteger != null && ageInteger != Number.NaN && ageMinimum != null || ageMaximum != null) {
- var ageValidMinimum = ageMinimum === null|| ageMinimum <= ageInteger;
- var ageValidMaximum = ageMaximum === null|| ageMaximum >= ageInteger;
- if (!ageValidMinimum || !ageValidMaximum) {
- /*
- var blockingElement = MV_createElement("a", {
- "style" : "display: block; position: absolute; left: 0; top: 0; width: 180px; height: 220px; opacity: 0.75; background-color: #ffffff; z-index: 20; text-decoration: none;"
- }, " ")
- blockingElement.setAttribute("href", linkElement.getAttribute("href"));
- profileNode.appendChild(blockingElement);
- */
- profileNode.setAttribute("style", "display: none;");
- }
- }
- // Highlight if country matches
- var country_listu = arraytoupper(country_list);
- var highlightCountriesPrefsValue = GM_getValue("marvinateHighlightLanguages");
- var highlightCountries = highlightCountriesPrefsValue === null ? null : highlightCountriesPrefsValue.split(",");
- var highlightCountriesu = arraytoupper(highlightCountries);
- var highlightCountryMatchFound = false;
- var iscountry = true;
- if (highlightCountries !== null) {
- var country = MV_getElementByPath("div[@class='details']//li[contains(@class, 'location')]", profileNode);
- country.setAttribute("style", "display: block;");
- var countryValue = country === null ? null : country.innerHTML;
- var countryarr = countryValue === null ? null : countryValue.split(",");
- for (var j = 0; j < countryarr.length; j++) {
- var countryValue = countryarr[j].trim();
- console.log(countryValue.toUpperCase().trim());
- if (isInArray(countryValue.toUpperCase().trim(), country_listu)) {
- var iscountry = true;
- if (isInArray(countryValue.toUpperCase().trim(), highlightCountriesu)) {
- //for (var j = 0; j < highlightCountries.length && !highlightCountryMatchFound; j++) {
- //var elementWithLanguage = profileNode//MV_getElementByPath("//dl/dd[contains(text(), '" + highlightCountries[j].trim() + "')]", pDetailPageRoot);
- // if (elementWithLanguage != null) {
- var highlightCountryMatchFound = true;
- profileNode.setAttribute("style", "background-color: #CDD9E5; border: 4px solid green; margin: -3px 4px 4px -3px; border-radius: 2px; ");
- // }
- }
- }
- }
- if (!highlightCountryMatchFound & iscountry & GM_getValue("hideothers") != false ) {
- profileNode.setAttribute("style", "display: none;");
- }
- }
- }
- function enhanceUserListingElementFromDetailPageInformation(profileNode, pDetailPageRoot, detailInfoElement) {
- /// var country_list = ["London","united kingdom","russian","united states","europe","Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Kyrgyz Republic","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Namibia","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre & Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","St. Lucia","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine","United Arab Emirates","United Kingdom","Uruguay","Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"];
- // Highlight if country matches
- var country_listu = arraytoupper(country_list);
- var highlightCountriesPrefsValue = GM_getValue("marvinateHighlightLanguages");
- var highlightCountries = highlightCountriesPrefsValue === null ? null : highlightCountriesPrefsValue.split(",");
- var highlightCountriesu = arraytoupper(highlightCountries);
- var highlightCountryMatchFound = false;
- var iscountry = true;
- var profilecountryValue = 0;
- if (highlightCountries !== null) {
- for (var j = 0; j < highlightCountries.length && !highlightCountryMatchFound; j++) {
- var elementWithLanguage = MV_getElementByPath("//dl/dd[contains(text(), '" + highlightCountries[j].trim() + "')]", pDetailPageRoot);
- if (elementWithLanguage !== null) {
- profilecountryValue = elementWithLanguage === null ? null : elementWithLanguage.innerHTML;
- highlightCountryMatchFound = true;
- // profileNode.setAttribute("style", "background-color: #CDD9E5; border: 6px solid red; margin: -3px 4px 4px -3px; border-radius: 2px; ");
- }
- }
- if (highlightCountryMatchFound) {
- //console.log(countryValue_str.toUpperCase().trim());
- //console.log(profilecountryValue.trim());
- profileNode.setAttribute("style", "display: block; background-color: #CDD9E5; border: 6px solid red; margin: -3px 4px 4px -3px; border-radius: 2px;");
- }
- }
- // Adjust the tipping information
- // var tipButtonNode = MV_getElementByPath("//a[@class='tip_button']", pDetailPageRoot);
- // detailInfoElement.setAttribute("class", tipButtonNode == null ? "marvinateDetailInfoDisabled" : "marvinateDetailInfoEnabled");
- // detailInfoElement.innerHTML = "€";
- }
- function isInArray(value, array) {
- return array.indexOf(value) > -1;
- }
- function arraytoupper(array) {
- return array.map(function (value) {
- return value.toUpperCase();
- });
- }
- function createLinkToNextPage(pNextPageNumber) {
- var nextPageArea = MV_createElement("ul", {
- "id": "marvinatePageArea_" + pNextPageNumber,
- "class": "list",
- "style": "font-weight: bold; "
- }, "");
- var nextPageLink = MV_createElement("a", {
- "id": "marvinatePageLink_" + pNextPageNumber,
- "href": "#",
- "style": "display: block; border: 1px solid #8BB3DA; margin: 10px 0px 10px 0px; padding: 5px;"
- }, "Load next page (page " + pNextPageNumber + ")");
- nextPageArea.appendChild(nextPageLink);
- var appendResultPageFunction = function () {
- // Show everyone we're busy
- var waitingElement = MV_createElement("div", {
- "style": "border: 1px solid #8BB3DA; margin: 10px 0px 10px 0px; padding: 5px;"
- }, "Loading page " + pNextPageNumber + "...");
- nextPageArea.removeChild(nextPageLink);
- nextPageArea.appendChild(waitingElement);
- var completeFunction = function (pElement, pRequest, pResponse) {
- nextPageArea.removeChild(waitingElement);
- nextPageArea.appendChild(MV_createElement("div", {
- "style": "border: 1px solid #8BB3DA; margin: 10px 0px 10px 0px; padding: 5px;"
- }, "Page: " + pNextPageNumber));
- pagingElement.parentNode.insertBefore(pElement, pagingElement);
- optimizeUserList();
- createLinkToNextPage(pNextPageNumber + 1);
- };
- var errorFunction = function (pRequest, pResponse, pException) {
- nextPageArea.removeChild(waitingElement);
- nextPageArea.appendChild(MV_createElement("div", {
- "style": "border: 1px solid #8BB3DA; margin: 10px 0px 10px 0px; padding: 5px;"
- }, "Cannot load page " + pNextPageNumber + " [" + pException + "]"));
- };
- // Load the next page
- var currentPageUrl = window.location.href;
- var lastSlashIndex = currentPageUrl.lastIndexOf("/");
- var nextPageUrl = currentPageUrl.substring(0, lastSlashIndex + 1) + "?page=" + pNextPageNumber;
- MV_sendRequest({
- url: nextPageUrl,
- xpath: "//ul[@class='list']",
- onComplete: completeFunction,
- onError: errorFunction
- });
- };
- nextPageLink.addEventListener("click", appendResultPageFunction, true);
- pagingElement.parentNode.insertBefore(nextPageArea, pagingElement);
- }
- // Append the next page link
- var pagingElement = MV_getElementByPath("//ul[@class='paging']");
- if (pagingElement !== null) {
- optimizeUserListListeners.push(function () {
- var activePageLink = MV_getElementByPath("li[@class='active']/a", pagingElement);
- if (activePageLink !== null) {
- var activePage = parseInt(activePageLink.innerHTML);
- createLinkToNextPage(activePage + 1);
- }
- });
- optimizeUserListListeners.push(function () {
- var currentPageUrl = window.location.href;
- var currentPageNeedle = "page=";
- var currentPageValueStartIndex = currentPageUrl.indexOf(currentPageNeedle);
- var currentPageValueEndIndex = currentPageValueStartIndex < 0 ? -1 : currentPageUrl.indexOf("&", currentPageValueStartIndex + 1);
- var currentPageValue = currentPageValueStartIndex < 0 ? 1 : parseInt(currentPageUrl.substring(currentPageValueStartIndex + currentPageNeedle.length, currentPageValueEndIndex < 0 ? currentPageUrl.length : currentPageValueEndIndex));
- var lastSlashIndex = currentPageUrl.lastIndexOf("/");
- var nextPageRootUrl = currentPageUrl.substring(0, lastSlashIndex + 1) + "?page=";
- var newPagingContent = MV_createElement("div");
- var appendTargetLinkFunction = function (pPageIndex) {
- var classValue = pPageIndex == currentPageValue ? "marvinateButton marvinateButtonActive" : "marvinateButton";
- var targetLinkElement = MV_createElement("a", {
- "class": classValue,
- "style": "margin: 0px 3px 0px 3px; padding: 6px 12px 5px 12px; ",
- "href": nextPageRootUrl + pPageIndex
- }, pPageIndex);
- newPagingContent.appendChild(targetLinkElement);
- };
- for (var i = 1; i <= currentPageValue + 3; i++) {
- appendTargetLinkFunction(i);
- }
- pagingElement.innerHTML = "";
- pagingElement.appendChild(newPagingContent);
- });
- }
- // Run the optimizations (called when the list page is loaded for the first
- // time)
- optimizeUserList();
- // =============================================================================
- // === Includes ================================================================
- // =============================================================================
- //
- // Include start [domUtil.js]
- /*
- function MV_removeElementsByPath(pPath) {
- var pathResult = document.evaluate(pPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- if(pathResult.snapshotLength > 0) {
- for(var i=0; i < pathResult.snapshotLength; i++) {
- var pathNode = pathResult.snapshotItem(i);
- pathNode.parentNode.removeChild(pathNode);
- }
- }
- }
- */
- function MV_getElementByPath(pPath, pRoot) {
- var pathResult = document.evaluate(pPath, pRoot === null ? document : pRoot, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- return pathResult.snapshotLength <= 0 ? null : pathResult.snapshotItem(0);
- }
- function MV_createButton(pAttributes, pClickListener) {
- pAttributes.type = "button";
- var resultElement = MV_createElement("input", pAttributes);
- if (pClickListener != null) {
- resultElement.addEventListener("click", pClickListener, true);
- }
- return resultElement;
- }
- function MV_createElement(pElementName, pAttributes, pInnerHtml) {
- var resultElement = document.createElement(pElementName);
- for (var attributeName in pAttributes) {
- resultElement.setAttribute(attributeName, pAttributes[attributeName]);
- }
- if (pInnerHtml != null) {
- resultElement.innerHTML = pInnerHtml;
- }
- return resultElement;
- }
- // Include end [domUtil.js]
- // Include start [xmlhttpUtil.js]
- /**
- * Sends the request to the remote system and evaluates the response which
- * must be valid HTML and contain a specified element identifiable by an XPath
- * expression
- *
- * Expected properties in the request are:
- * url
- * the URL to which the request will be made
- * xpath
- * the XPath expression that must evaluate to an element that will be
- * extracted from the response received by the remote system
- * onComplete
- * a function that will be called when the result has been received and the
- * content should be displayed
- * onError
- * a function that will be called if the request cannot be sent or the
- * response received is invalid
- */
- function MV_sendRequest(pRequest) {
- var processResponse = function (pResponse) {
- var responseHtmlStart = pResponse.responseText.indexOf("<html");
- var responseHtmlEnd = pResponse.responseText.indexOf("</html>");
- if (responseHtmlStart < 0 || responseHtmlEnd < 0) {
- pRequest.onError(pRequest, pResponse, "Invalid HTML document received");
- } else {
- var responseHtmlElement = document.createElement("html");
- responseHtmlElement.innerHTML = pResponse.responseText.substring(responseHtmlStart, responseHtmlEnd + "</html>".length);
- var responseXpathResult = document.evaluate(pRequest.xpath, responseHtmlElement, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- if (responseXpathResult.snapshotLength <= 0) {
- pRequest.onError(pRequest, pResponse, "Invalid HTML document received");
- } else {
- pRequest.onComplete(responseXpathResult.snapshotItem(0), pRequest, pResponse);
- }
- }
- };
- try {
- GM_xmlhttpRequest({
- method: "GET",
- url: pRequest.url,
- onload: processResponse,
- onerror: function (pResponse) {
- pRequest.onError(pRequest, pResponse, null);
- }
- });
- } catch (e) {
- pRequest.onError(pRequest, null, e);
- }
- }
- // Include end [xmlhttpUtil.js]
- $(document).ready(function () {
- $('.list').parent().bind("DOMNodeInserted", function () {
- if (!refreshThePeopleListRunning) {
- console.log("refresh");
- optimizeUserList();
- console.log("refresh done");
- }
- });
- //$('.list').parent().bind("DOMNodeRemoved",function(){
- //console.log('DOMNodeRemoved');
- //});
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement