Wpis z mikrobloga

Jeśli brakuje Wam obserwujących podczas autouzupełniania tagów/użytkowników, można użyć skrypt, który właśnie stworzyłem! Jeśli ktoś ma pomysł, jak sprawić, by odświeżał się nawet wtedy, gdy okno już jest widoczne, dajcie znać.. obecnie można na przykład dodać spacje i backspace, aby „odświeżyć” listę

Widzę, że niestety #nowywykop dodał ()[] dookoła linki w codeblock.. trzeba będzie usuwać i zostawić tylko linki jak chcecie skorzystać (°°

EDIT: lepiej będzie przez link.. https://pastebin.com/raw/RzixnvXf

#userscript #greasemonkey #tampermonkey #wykopchangelog

// ==UserScript==
// @name Wykop 2.0 AutoCompleteFollowerCount
// @namespace [https://wykop.pl/ludzie/xXdeepfriedXx](https://wykop.pl/ludzie/xXdeepfriedXx)
// @version 1.0
// @description Add the amount of followers to the autocomplete window
// @Author xXdeepfriedXx
// @Match *.wykop.pl/*
// @Icon [https://www.google.com/s2/favicons?sz=64&domain=wykop.pl](https://www.google.com/s2/favicons?sz=64&domain=wykop.pl)
// @grant none
// @require [http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js](http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js)
// @require [https://gist.github.com/raw/2625891/waitForKeyElements.js](https://gist.github.com/raw/2625891/waitForKeyElements.js)
// ==/UserScript==

waitForKeyElements(".inline-autocomplete-stream", newAutoCompleteWindowAdded);

const tagsAutocompleteURL = "[https://wykop.pl/api/v3/tags/"](https://wykop.pl/api/v3/tags/")
const profilesAutocompleteURL = "[https://wykop.pl/api/v3/profile/users/"](https://wykop.pl/api/v3/profile/users/")

function newAutoCompleteWindowAdded(element) {
let suggestions = element[0].getElementsByTagName('span');
if (typeof this.lastFingerPrint == "undefined" || this.lastCount != suggestions.length || this.lastFingerPrint != getTagsFingerPrint(suggestions)) {
for (let i = 0; i < suggestions.length; i++) {
let suggestion = suggestions[i];
getObserveCount(suggestion);
}
}
this.lastFingerPrint = getTagsFingerPrint(suggestions);
this.lastCount = suggestions.length
return true;
}

function getTagsFingerPrint(suggestions) {
let fingerPrint = '';
for (let i = 0; i < suggestions.length; i++) {
let suggestion = suggestions[i];
fingerPrint += suggestion.innerText.substring(1,).split(' ')[0];
}
return fingerPrint;
}

function getObserveCount(element) {
var type = element.innerText.substring(0,1);
var query = element.innerText.substring(1,);
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var details = JSON.parse(this.responseText);
addCount(type, element, details.data)
}
};
xmlhttp.open("GET", (type === '@' ? profilesAutocompleteURL : tagsAutocompleteURL) + query);
xmlhttp.setRequestHeader("Authorization", "Bearer " + window.localStorage.token)
xmlhttp.send();
}

function addCount(type, element, data) {
const name = (type === '@' ? data.username : data.name)
const followers = (type === '@' ? data.summary.followers : data.followers)
element.innerText = `${type}${name} (${followers})`;
}
xXdeepfriedXx - Jeśli brakuje Wam obserwujących podczas autouzupełniania tagów/użytko...

źródło: autocomplete

Pobierz
  • 2