Greasy Fork is available in English.
Vote on posts on /g/.
当前为
Adds voting to 4chan's /g/.
-- Voting script
-- 0.0.0.2
-- License: CC0; https://creativecommons.org/publicdomain/zero/1.0/
local thread = request.query.id
local vote = (request.query.vote == "up" and 1) or
(request.query.vote == "down" and -1) or
0
local ip = request.remote_addr
local ip_key = "voted:" .. thread .. ":" .. ip
local vote_key = "score:" .. thread
local voted = false
if not ((vote == 0) or storage[ip_key]) then
if not storage[vote_key] then
storage[vote_key] = 0
end
storage[vote_key] = storage[vote_key] + vote
storage[ip_key] = true
voted = true
end
local response = {voted = (voted and 1 or 0), score = storage[vote_key] or 0}
return json.stringify(response)