Greasy Fork is available in English.

Le Upboat! xD

Vote on posts on /g/.

Yazar
garyoak
Günlük kurulumlar
0
Toplam kurulumlar
133
Değerlendirmeler
0 0 0
Versiyon
0.0.2.4
Oluşturulma
06.09.2014
Güncellenme
07.09.2014
Lisans
CC0
Geçerli

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.

Original backend script for the webscript.io platform (Lua)


-- 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)