Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const factoryDefaults = {
- blocked: [],
- dba: ''
- }
- const Parser = new DOMParser();
- const Data = getLocalData();
- function get_userid(username) {
- return new Promise(async (res, rej) => {
- let data = await $.get(`https://www.fxp.co.il/member.php?username=${username}`);
- let doc = Parser.parseFromString(data, 'text/html');
- try {
- let uid = $(doc).find('.userprof_content>dl>dd>a').attr('href').substr(35);
- res(uid);
- } catch(ex) { rej('User doesn\'t exist'); }
- });
- }
- function get_username(userid) {
- return new Promise(async (res, rej) => {
- let data = await $.get(`https://www.fxp.co.il/member.php?u=${userid}`);
- let doc = Parser.parseFromString(data, 'text/html');
- let un = $(doc).find('.member_username').text().trim();
- if(un === '') rej('User doesn\'t exist');
- else res(un);
- });
- }
- function getLocalData() {
- let data;
- try {
- data = JSON.parse(localStorage.fxpblockplus);
- } catch(ex) {
- data = factoryDefaults;
- }
- return data;
- }
- function saveData() {
- localStorage.fxpblockplus = JSON.stringify(Data);
- }
- function menuOption() {
- let option = $('#yui-gen0').children().last().prev();
- let sepHtml = $('<div>').append(option.clone()).html();
- option.before(sepHtml);
- option.before('<div style="height: 15px;"><a href="javascript:" id="blockplus">הגדרות Block+</a></div>');
- }
- function createMenu() {
- let menuCss =
- `<style>
- #blockplus-menu {
- width: 400px;
- height: 350px;
- z-index: 9999;
- position: fixed;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- background-color: white;
- }
- #blockplus-menu > div {
- margin: 10px;
- }
- #blocked-users {
- width: 100%;
- min-height: 200px;
- margin-bottom: 5px;
- }
- #blockplus-menu button {
- padding: 5px 10px;
- font-size: 12pt;
- margin-bottom: 8px;
- }
- #userblockname {
- width: 83%;
- height: 28px;
- font-size: 14pt;
- border: solid 1px #6b91ab;
- outline: none;
- }
- #adduser {
- float: left;
- }
- #remusers, #closeusers {
- width: 100%;
- }
- </style>`;
- $('head').append(menuCss);
- let menuHtml =
- `<div id="blockplus-menu" style="display: none;">
- <div>
- <label for="blocked-users">משתמשים חסומים:</label>
- <select multiple id="blocked-users">
- </select>
- <input type="text" id="userblockname" />
- <button id="adduser">הוסף</button><br/>
- <button id="remusers" disabled>מחק בחירה</button>
- <button id="closeusers" onclick="$('#blockplus-menu').hide()">סגור</button>
- </div>
- </div>`
- $('body').append(menuHtml);
- bindEvents();
- refreshUsers();
- }
- function refreshUsers() {
- $('#blocked-users').children().remove();
- Data.blocked.forEach(async u => {
- let username = await get_username(u);
- $('#blocked-users').append(`<option>${username} - ${u}</option>`);
- });
- }
- function bindEvents() {
- $('#blockplus').click(() => {
- $('#blockplus-menu').show();
- $('#yui-gen1').get(0).click();
- });
- $('#adduser').click(async () => {
- $('#adduser').attr('disabled', true);
- let username = $('#userblockname').val();
- let userid;
- try {
- $('#userblockname').val('');
- userid = await get_userid(username);
- } catch(ex) {
- alert('המשתמש הזה לא קיים או שהוא בבאן!');
- $('#adduser').removeAttr('disabled');
- return;
- }
- $('#adduser').removeAttr('disabled');
- if(Data.blocked.includes(userid)) {
- alert("המשתמש הזה כבר קיים ברשימת החסומים!");
- return;
- }
- Data.blocked.push(userid);
- refreshUsers();
- });
- $('#blocked-users').change(() => {
- let users = $('#blocked-users').val();
- (users !== null) ?
- $('#remusers').removeAttr('disabled') :
- $('#remusers').attr('disabled', true);
- });
- $('#remusers').click(() => {
- let users = $('#blocked-users').val();
- if(users !== null) {
- let uids = [];
- users.forEach(u => {
- uids.push(u.split(' - ')[1]);
- });
- Data.blocked = Data.blocked.filter(u => {
- return uids.indexOf(u) === -1;
- });
- refreshUsers();
- $('#remusers').attr('disabled', true);
- }
- });
- blockUsers();
- }
- function blockUsers() {
- let path = location.pathname;
- if(path === "/forumdisplay.php") {
- $('.threadbit').each((_, t) => {
- let uid = $(t).find('.label a').attr('href');
- Data.blocked.forEach(u => {
- if(uid.includes(u)) {
- $(t).remove();
- }
- });
- });
- }
- }
- function Init() {
- $(window).unload(() => {
- saveData();
- });
- menuOption();
- createMenu();
- }
- $(Init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement