Greasy Fork

Greasy Fork is available in English.

Le Upboat! xD

Vote on posts on /g/.

当前为 2014-09-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
garyoak
评分
0 0 0
版本
0.0.2.3
创建于
2014-09-06
更新于
2014-09-07
大小
17.5 KB
许可证
CC0
适用于

Adds voting to 4chan's /g/ and [s4s].

Donate: D5joR77pSWxDvjEmteAPh9Cq53GoBAR5aE

Backend script for webscript.io platform


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