您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Vote on posts on /g/.
Adds voting to 4chan's /g/ and [s4s].
Donate: D5joR77pSWxDvjEmteAPh9Cq53GoBAR5aE
Update: the backend is dead. Feel free to fork and host on your own elsewhere.
-- Voting script
-- 0.0.1.1
-- License: CC0; https://creativecommons.org/publicdomain/zero/1.0/
-- functions
function thread_score(thread)
return storage["score:" .. thread] or 0
end
function cast_vote(thread, ip, vote)
storage["score:" .. thread] = (storage["score:" .. thread] or 0) + vote
storage["voted:" .. thread .. ":" .. ip] = true
end
function has_voted(thread, ip)
return storage["voted:" .. thread .. ":" .. ip]
end
-- main body
local threads = {}
for key, value in pairs(request.query) do
if string.find(key, 'id') then
table.insert(threads, value)
end
end
local thread = threads[1]
local vote = (request.query.vote == "up" and 1) or
(request.query.vote == "down" and -1) or
0
local ip = request.remote_addr
local voted_now = false
if not ((vote == 0) or has_voted(thread, ip)) then
cast_vote(thread, ip, vote)
voted_now = true
end
local scores = {}
for i = 1, #threads do
scores[threads[i]] = thread_score(threads[i])
end
response = {voted = (voted_now and 1 or 0), scores = scores}
return json.stringify(response)