[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

greentext function for website?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 33
Thread images: 3

File: py3254uip9r328nrewqi79r832.png (42KB, 320x320px) Image search: [Google]
py3254uip9r328nrewqi79r832.png
42KB, 320x320px
Hi, /wsr/, is there a way I can use css to make text green whenever I type a
>
on my website like the greentext on 4chan?

How would one go about implementing greentext into their website?
>>
>>260255
bump pls help
>>
there was a "contains" selector that never made it to spec and it worked globally, not just start-with
there is a "attribute starts with" [data-someattributename^=">"] selector, but you would have to populate the data-someattributename field to accomplish this
why not just add a green-text class (color: green) for <div>'s/<p>'s (server or client side) whose textContent starts with ">"?
>>
>>260325
I was just trying to make a 4chan clone because I was bored.

I did it in a really shitty way where I used a text document to store threads and replies.

I was just wondering if there was already a way to automatically check the text on the page for ">"'s instead of having to make a function that manually inserts a <p> or a <div> in front of each one.
>>
>>260331
how do you parse those text files? they still get output as html right? are you using some dynamic approach to serving this content (php, asp, java, etc.)? or just serving those files content verbatim? if you are copying the contents directly from the html served by 4chan then the greentext already has the proper class applied to it: <span class="quote">&gt;</span>
and you just need to add the class quote to your xml:
.quote { color: #789922 }

im still not entirely sure of your setup though
>>
>>260336
>xml
*css
>brainfart
>>
>>260336
I'm not using any of 4chan's code. It's entirely hand coded by me. I'm just using php to throw the text file in the middle of the page. It still gets output as html. When you post, php writes it to the file, then the page is updated and you see your post.
>>
>>
>I'm not using any of 4chan's code.
thats not what i meant, im asking how do you extract the post/threads from 4chan? do you scrape the web/html interface or are you using the json api?
>I'm just using php
>When you post, php writes it to the file
depending on how you are storing the thread/posts on those texts files php might come in handy. can you post your text file content for this thread, for instance? is it just html inside the text file?
>>
>>260349
I don't. this has no 4chan posts on it. Its all test posts made by me.

sorry for spaghetti code. I'm kinda self teaching myself this as I go. I had no idea how to html or php before this. pls no bully.

pt 1

<?php
function reply($comment, $file){
$handle = fopen("$file","a");
fwrite($handle,"<p>__<b>Anonymous</b>__</br>" . $comment . "</br></br></p>");
fclose($handle);
}

if(isset($_POST['postThread'])){
$title = htmlspecialchars($_POST['title']);
$comment = htmlspecialchars($_POST['comment']);
$handle = fopen("comments.txt","r+");
$threadNum = fopen("nums.txt","a");
fwrite($threadNum, "1");
$num = file_get_contents("nums.txt");
fclose($threadNum);
$prevthreads = file_get_contents("comments.txt");
$thread = fopen(strlen($num).".txt","a");
fwrite($thread, "<p></br>__<b>Original Poster</b>__</br>" . $comment . "</br></br></p><form action = '' method = 'POST'><input name = 'threadNum' value = '" . strlen($num) . "' type = 'hidden'><textarea cols = '28' rows = '5' name = 'comment' ></textarea> <input name = 'postReply' type = 'submit' value = 'Post'></form></br>");
fwrite($handle, "<div id = '".strlen($num)."'>__________</br><b><a href = '#content".strlen($num)."' onClick = 'myFunction(\"content".strlen($num)."\")' >Thread #" . strlen($num) . ": " . $title . "</b></a></br><p>".substr($comment,0,50)."</p><div id = 'content".strlen($num)."' style ='display: none;'><?php include '" . strlen($num) . ".txt' ?></div></br></div>" . $prevthreads);
fclose($handle);
}

if(isset($_POST['postReply'])){
$number = $_POST['threadNum'];
reply(htmlspecialchars($_POST['comment']), $number . ".txt");
}
?>
>>
>>260350
pt 2

<html>
<head>
<title>The Bobo Cavern /b/-Random</title>
<style type="text/css">
<!--
A{text-decoration:none}
-->
p{
}
</style>
</head>
<body bgcolor = "222222" link = "AAAAFF" vlink = "AAAAFF" alink = "444488">

<script type = "text/javascript">
function myFunction(div) {
var x = document.getElementById(div);
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>

<tt><pre><h2><font color = "white"><center>The Bobo Cavern
/a/<a href="Random.php">b</a>/g/m/n/oc/p/r/s/

___ __ ___ _
/ / |__ / / ___ | _ \__ _ _ _ __| |___ _ __
/ /| '_ \/ / |___| | / _` | ' \/ _` / _ \ ' \
/_/ |_.__/_/ |_|_\__,_|_|\_\__,_\___/_|_|_|
/b/ is a board where you can post anything.</center>
</h2><center></font><font size = "+2" color = "white">
<b>Make New Thread:</b><form action = "" method = "POST">Title:
<input type = "text" name = "title"> </textarea><input name = "postThread" type = "submit" value = "Post">
Comment:
<textarea cols = "28" rows = "5" name = "comment"></textarea></form>[<a href="BoboCavern.html">Home</a>]

<b>Threads:</b>
<?php include "comments.txt" ?>

[<a href="<?php echo 'localhost/BoboCavernPages/BoboCavern.html'?>">Home</a>]

<b>Themes: Radio:
<select>
<option value = "BW">B and W</option>
<option value = "NT">Nighttime</option>
<option value = "CL">Classic</option>
<option value = "ER">Eyerape</option>
</select> <input type = "radio" name = "group1" value = "ON">On <input type = "radio" name = "group1" value = "OFF" checked>Off

/a/<a href="Random.php">b</a>/g/m/n/oc/p/r/s/</b></p>
</center>
</font>
</pre>
</tt>
</body>
</html>
>>
ignore >>260349, i just re-read op and realized you arent even using the posts from 4chan...

on your post method parser, before you write to the file, parse the lines and if a line starts with ">", do
line = '<p style="color: #789922">' . line . '</p>';
then reassemble all the text together again (add all the lines with "\n" between then) and save on the file just like you do now
>>
>>260350
>no bully
alright, add:

$lines = explode("\n", $comment);
foreach ($lines as $line)
{
if (substr($comment, 0, 4) === '&gt;')
$line = '<p style="color: #789922">' . line . '</p>';
}
$comment = '';
foreach ($lines as $line)
{
$comment .= $line . "\n";
}

at the start of your reply function, and test to see if it works/fits-your-needs
i didnt test any of that, btw
>>
>>260360
>if (substr($comment, 0, 4) === '&gt;')
should be
if (substr($line, 0, 4) === '&gt;')
>>
File: Screenshot (31).png (16KB, 920x514px) Image search: [Google]
Screenshot (31).png
16KB, 920x514px
>>260360
did not seem to work. I might mess around with what you wrote and see if I can get it to work. So it does look like I need to use a for loop and substrings. Thanks for pointing me in a direction.
>>
>>260370
>did not seem to work
try:

$lines = explode("\n", $comment);
for ($i = 0; $i < count($lines); $i++)
{
$line = $lines[$i];
if (substr($line, 0, 4) === '&gt;')
{
$line = '<p style="color: #789922">' . $line . '</p>';
$lines[$i] = $line;
}
}
$comment = '';
foreach ($lines as $line)
{
$comment .= $line . "\n";
}

instead, this should work
gl

>t. brainfarting over no sleep
>>
File: Screenshot (33).png (16KB, 494x540px) Image search: [Google]
Screenshot (33).png
16KB, 494x540px
>>260387
it worked!
Thanks dude you're a real bro
>>
>>260331
I'm making a 4chan clone too out of boredom, are you me?
Also I basically used the same method as you, however while I can make posts I don't know how to reply to them or create specific folders for each thread. How did you do it?
>>
>>260387
>>260395
Nice work guys.
>>
>>260469
So the board has its own folder. Then all of the coding is on one page.

I also have a dext document that stores links to each current thread, and a text document that is used too store thread numbers.
The thread numbers doc just adds a 1 to the end of the document each time, and the thread's number is the string length of the thread numbers doc.
Whenever a new thread is made, it also gets its own document with its number as the title. That's where I store the op comment, the reply to thread textarea form, and the thread replies. Replying directly to each other is yet another hurdle I will be having to jump over, but I may try to use the code that anon wrote to do greenext to search the thread for the exact comment and link to it. I'm not sure yet.
As for having everything neatly on one page, where it all doesn't take up a whole bunch of space, I used a javascript function that opens and closes divs that you tell it to. So just set your threads inside divs and use the thread number as the div id. You will need to code the link to onClick call the javascript function.

All of my code for this entire project, minus the greentext is in this thread if you're interested in seeing for yourself. Just please don't steal it. Its spaghetti code that I taught myself so It isn't exactly nice to look at.
Have fun.
>>
>>260605
>Its spaghetti code that I taught myself
Same here. My php is similar to yours, except I use "a" intead of "r+t".

How do you avoid double threads upon refresh? I thought of just adding a captcha.
>>
>>260714
I don't. I just make a new thread, and it prevents doubling up. I haven't figured that out quite yet.
The "r+" is intentional, as it rewrites the entire text document instead of adding to it. This is useful in some cases, like when you want new threads to appear on top.
I do not know how to add a captcha either, however, I will probably look up a way to add a timer between posts, once I am close to the end, to prevent spamming, if I was to ever make this a real thing.
>>
>>260714
Oh yeah, I have my test board in one folder and the home page in the folder outside of it. How would you go about accessing home page in the outside folder? My link currently doesn't work.
>>
>>260756
Do you use XAMPP?
>>
>>260758
yeah I do.
>>
>>260762
Well my folders go like this:
htdocs/MainFolder/Index.php

htdocs/MainFolder/BoardName/board.php

From the index page i link it like this:

<a href="BoardName/board.php>Board</a>
>>
>>260766
Yeah I got that, but how do you go from
BoardName/board.php
back to index.php
>>
WHY IN GODS NAME WOULD YOU BE WILLINGLY USING PHP?
>>
>>260787
what else would I use for a website like this? I'm not well versed in the realm of technology, so I'm just using what 4chan used, in order to make a 4chan clone.
>>
>>260777

href="localhost/Mainfolder" works for me.
>>
>>260792
huh. Whenever I do that, it just slams localhost/Mainfolder onto the end of the url, resulting in the abomination that is
localhost/Mainfolder/BoardName/localhost/MainFolder/index.html
Maybe I'm not doing something right.
>>
>>260796
try changing the .html to .php, i think i had the same problem once.
>>
>>260802
It worked great! Thanks dude
>>
>>260806
No problemo. Glad I could help.
Thread posts: 33
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.