Skip to content

Instantly share code, notes, and snippets.

@xen0n
Created October 17, 2013 09:00
Show Gist options
  • Save xen0n/7021560 to your computer and use it in GitHub Desktop.
Save xen0n/7021560 to your computer and use it in GitHub Desktop.
experimental Renren userscript to enable self-voting on the hui.renren.com/daren13 campaign for fun
// ==UserScript==
// @name NanNvShen Self Voting
// @namespace name.xen0n
// @description Enables self-voting on hui.renren.com/daren13 campaign.
// @include http://hui.renren.com/daren13/user/profile*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
/*
// log helper
function log_d() {
"use strict";
if (console && console.log) {
return console.log.apply(this, arguments);
}
}
*/
// this mimics the mechanism described in profileWin.js of the app,
// to replace one help button's click event logic with the support button's.
var BTN_SUPPORT_ID = 'btn_support',
BTN_LEVELUP_ID = 'btn_levelup'
TITLE_INFO_EXPR = 'spotlight .info_in .ilblk a',
APP_MODULE_FILE_RE = /profileWin\.js/,
USER_ID_RE = /\?id=(\d+)$/,
SCRIPT_HANDLER = function(e) {
"use strict";
// for external script:
var src = e.target.src;
// log_d(src);
if (src.search(APP_MODULE_FILE_RE) != -1) {
// log_d('manipulation started');
var supportElem = document.getElementById(BTN_SUPPORT_ID),
levelupElem = document.getElementById(BTN_LEVELUP_ID),
titleElem = $(TITLE_INFO_EXPR);
// log_d("support elem:", supportElem);
// log_d("levelup elem:", levelupElem);
// log_d("title elem:", titleElem);
if (levelupElem !== null && supportElem === null) {
// profile page of oneself, no #btn_support.
// 开搞
// first set ID to support button's
// log_d("start processing");
levelupElem.id = BTN_SUPPORT_ID;
// then get full user name and user ID needed by the button's
// click event listener
// a. username
levelupElem.dataset.username = titleElem.title;
// b. userid
var uidMatch = titleElem.href.match(USER_ID_RE);
if (uidMatch !== null) {
var uid = uidMatch[1];
levelupElem.dataset.userid = uid;
}
}
// only execute this piece of code once
window.removeEventListener(e.type, SCRIPT_HANDLER, true);
}
};
// execute right before the main app module
// with help from http://userscripts.org/scripts/show/125936
window.addEventListener('beforescriptexecute', SCRIPT_HANDLER, true);
// vim:set ai et ts=2 sw=2 sts=2 fenc=utf-8:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment