当我收到一个页面访问时,它会自动发送一个好友请求

When I receive a page visit, it automatically sends a friend request

本文关键字:一个 好友请求 访问      更新时间:2023-09-26

所以当有人在网站上查看我的个人资料:playcraftmc.com/profile/1252121

它使那个人自动向我发送好友请求。以下是我到目前为止写的。

<script> Enjin_Profile_Friends.gi().followUser(1252121) </script>

现在它工作了,它使用户发送一个朋友请求,如果他们登录,除了它保持刷新页面。我对js很陌生,我不知道你是否可以让它只执行一次脚本。

顺便说一下,我有这个网站的管理员权限,这段代码直接嵌入到网站中。

让我们看看源代码是什么样子的:

> Enjin_Profile_Friends.gi().followUser
function(user_id) {
    $.post('/ajax.php?s=friends', {
        op: 'add',
        user_id: user_id
    }, function(result) {
        if (result.error != undefined && result.error) Enjin_Core.alert(result.error);
        else document.location.reload();
    }, 'json');
}

删除你不需要的部分:

function(user_id) {
    $.post('/ajax.php?s=friends', {
        op: 'add',
        user_id: user_id
    }, 'json');
}

它应该工作:

<script type="text/javascript">
    $.post('/ajax.php?s=friends', {
        op: 'add',
        user_id: '1252121'
    }, 'json');
</script>