Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalizando #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Extensao-Navegador-SnitchBot

go 1.18
Empty file added go.sum
Empty file.
12 changes: 12 additions & 0 deletions interface/accesses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[{
"name1" : "",
"name2" : "",
"name3" : "",
"name4" : "",
"name5" : "",
"name6" : "",
"name7" : "",
"name8" : "",
"name9" : "",
"name10" : ""
}]
32 changes: 32 additions & 0 deletions interface/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>SnitchBot</title>
</head>
<body>
<h2>SnitchBot</h2>
<p class="texts">Esses são seus 10 últimos acessos:</p>
<ol>
<li>Acesso1<span class="pegabot-bot-probability">%</span></li>
<li>Acesso2<span class="pegabot-bot-probability">%</span></li>
<li>Acesso3<span class="pegabot-bot-probability">%</span></li>
<li>Acesso4<span class="pegabot-bot-probability">%</span></li>
<li>Acesso5<span class="pegabot-bot-probability">%</span></li>
<li>Acesso6<span class="pegabot-bot-probability">%</span></li>
<li>Acesso7<span class="pegabot-bot-probability">%</span></li>
<li>Acesso8<span class="pegabot-bot-probability">%</span></li>
<li>Acesso9<span class="pegabot-bot-probability">%</span></li>
<li>Acesso10<span class="pegabot-bot-probability">%</span></li>
</ol>
<p class="texts">O percentual de contas com alta probabilidade de ser bot é:</p>
<div id="progress-information">
<progress max="1" value="0.5"></progress>
<span id="mean-bot-probability">%</span>
</div>
<script type="module" src="script.js"></script>
<script type="application/json" src="accesses.json"></script>
</body>
</html>
124 changes: 124 additions & 0 deletions interface/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as fileSystem from './accesses.json' assert { type: "json" };

var lastTenAccessesArray = []
var jsonObject

class Node {
constructor(value){
this.value = value;
this.next = null;
}
}

class Queue {
constructor() {
this.first = null
this.last = null
this.size = 0
}
enqueue(value){
let newNode = new Node(value)
if(this.first === null){
this.first = newNode
}else{
let current = this.first
while(current.next != null){
current = current.next
}
current.next = newNode
}
this.size++
}
dequeue(){
let current = this.first
this.first = current.next
this.size--
return current.value
}
find(position){
let current = this.first
let cont = 0
if(current.value === null){
return null
}
while (cont < position) {
current = current.next
cont++
}
return current.value
}
}

var url
function getURL(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab = tabs[0];
url = tab.url;
});
}

var accessesQueue = new Queue()
chrome.tabs.onUpdated.addListener(() => {
getURL()
if(isTwitterAccount(String(url))){
var auxNodeValue
if(accessesQueue.size == 0){
auxNodeValue = null
}else{
auxNodeValue = accessesQueue.find(accessesQueue.size - 1)
}
if(getHandle(String(url)) != auxNodeValue && !(auxNodeValue == null && accessesQueue.size > 0)){
if(accessesQueue.size == 10){
accessesQueue.dequeue()
accessesQueue.enqueue(getHandle(String(url)))
}else{
accessesQueue.enqueue(getHandle(String(url)))
handleStorageOnArray()
}
handleStorageOnArray()
console.log(fileSystem[0])
}
}
})

function handleStorageOnArray(){
for (let i = 0; i < accessesQueue.size; i++) {
if(accessesQueue.find(i) === null){
lastTenAccessesArray[i] = null
}else{
lastTenAccessesArray[i] = accessesQueue.find(i)
}
}
return lastTenAccessesArray
}

function creatingJSONObject(array){
var jsonString = ""
for (let i = 0; i < array.length; i++) {
jsonString = jsonString + '"'
+'access' + String(i)
+'": "'
+ array[i]
+'",';
}
console.log(jsonString)
jsonObject = JSON.parse("{" + jsonString.substring(0,jsonString.length - 1) + "}")
return jsonObject
}

function getHandle(url){
var handle
if(isTwitterAccount(url)){
handle = url.substring(url.length, url.lastIndexOf('/') + 1)
}
return handle
}

function isTwitterAccount(url){
var regex = /^(https\:\/\/twitter\.com\/)/
var isTwitterAccount = false
if(regex.test(url)){
isTwitterAccount = true
}
return isTwitterAccount
}
81 changes: 81 additions & 0 deletions interface/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
*{
margin: 0;
box-sizing: border-box;
padding: 0;
font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 16px;
}

html{
width: fit-content;
height: fit-content;
padding: 2vh;
}

body{
width: inherit;
height: inherit;
}

h2{
font-size: 200%;
margin-bottom: 2vh;
}

ol{
margin: 1vh 0;
display: flex;
flex-direction: column;
justify-content:space-between;
align-items:stretch;
gap: 1.5vh;
list-style: none;
height: fit-content;
}

li{
height: fit-content;
padding: 1vh;
position: relative;
transition: all .3s;
border-left: 1vh solid blueviolet;
}

.pegabot-bot-probability{
position: absolute;
right: 1vh;
display: inline-block;
}

li:hover{
cursor: pointer;
font-weight: bold;
padding: 1vh 2vh;
border-left: 1.5vh solid blueviolet;
}

.texts{
white-space: nowrap;
}

#progress-information{
display: flex;
flex-direction: row;
justify-content: center;
gap: 1.5vh;
align-items: center ;
}

progress{
height: 7vh;
width: 50%;
}
progress::-webkit-progress-value{
background:gold;
}
progress::-webkit-progress-bar{
background:gold;
}
progress::-moz-progress-bar{
background:gold;
}
80 changes: 80 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"regexp"

_ "github.com/go-sql-driver/mysql"
)

type Name struct {
Name string `json:"name,omitempty"`
}


func main() {
content, err := ioutil.ReadFile("test.json")
if err != nil {
fmt.Println(err.Error())
}

var Names []Name
err2 := json.Unmarshal(content, &Names)
if err2 != nil {
fmt.Println("Error JSON Unmarshalling")
fmt.Println(err2.Error())
}

db, erro := sql.Open("mysql", "root:@/?charset=utf8&parseTime=True&loc=Local")
if erro != nil{
panic(erro.Error())
}
defer db.Close()

for _, x := range Names {

statement, erro := db.Prepare(
"insert into names (name) values (?)",
)
if erro != nil {
panic(erro.Error())
}
defer statement.Close()

_, erro = statement.Exec(x.Name)
if erro != nil {
panic(erro.Error())
}

urlA, err := url.Parse("https://backend.pegabot.com.br/botometer?socialnetwork=twitter&profile=otaviouss&search_for=profile&limit=1")
if err != nil {
log.Fatal(err)
}

values := urlA.Query()

values.Set("profile", x.Name)

urlA.RawQuery = values.Encode()

resp, err := http.Get(urlA.String()); if err != nil { log . Fatalln ( err ) }
body, err := ioutil.ReadAll(resp.Body); if err != nil {log.Fatal(err)}

sb := string (body);

r := regexp.MustCompile(`""all"\:0\.\d+,|"all"\:1\.0+,"`)

results := r.FindAllString(sb, -1)
for i := range(results) {
fmt.Println(results[i])
}


}
}
14 changes: 14 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"manifest_version": 3,
"name": "SnitchBot",
"version": "1.0",
"description": "SnitchBot é um delator de perfis bot que deixa o usuário atualizado através de dados capturados da ferramenta Pegabot sobre como ele está sendo enganado por perfis automatizados no Twitter",
"author": "Grupo 2D do Hackathon Pegabot 2022",
"action": {
"default_title": "SnitchBot",
"default_popup": "interface/index.html"
},
"permissions": [
"tabs"
]
}
10 changes: 10 additions & 0 deletions sql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE DATABASE IF NOT EXISTS test;
USE test;

DROP TABLE IF EXISTS names;


CREATE TABLE names(
id int auto_increment primary key,
nome varchar(50) not null
) ENGINE=INNODB;
6 changes: 6 additions & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"nome": "@laisvol6"
}

]