Wikia

Community Central

Admin Forum:Javascript last URL (spoiler reveal choice)

18,698pages on
this wiki
Talk0

This Forum has been archived

Forums: Admin Central Index Technical Help Javascript last URL (spoiler reveal choice)
Wikia's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Note: This topic has been unedited for 1298 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.



I know almost nothing about javascript (<HEAD>, <BODY>, <a href>). I want to be able to make a verbatim that outputs the previous URL, so if the previous URL is the "spoiler" page, it would show the content, if not it would link to it. The spoiler page would link to the last page. Thanks, Iggyvolz 01:19, March 24, 2012 (UTC)

(<HEAD>, <BODY>, <a href>) have nothing to do with Javascript. If that's all you know, you don't really know anything about HTML either, since those things are HTML. 65.92.180.188 04:51, March 24, 2012 (UTC)
You want a complete solution, don't you? :)
Below is a little snippet from my jQuery grab bag. It's not exactly what you were asking for, but it serves the same purpose. It checks if the word "spoiler" appears in the page's title and if so, it blackens the page and displays a dialog that will either send the visitor back or reveal the page.
$(function () {
    if (/spoiler/i.test($('title').text())) {
        $('body').append(
        '<div id="blackout" style="position: absolute; top: 0; left: 0; width: 100%; height: ' + $(document).height() + 'px; opacity: 1.0; background-color: black; z-index: 1000;">' +
            '<table id="dialog" border="0" cellpadding="20" style="position: absolute; left: 50%; width: 500px; margin-left: -250px; top: ' + parseInt($(window).height()/2 - 75) + 'px; height: 150px; background-color: white;">' +
                '<tr>' +
                    '<td colspan="2" style="text-align: center;">This page contains spoilers. Are you sure you want to read it?</td>' +
                '</tr>' +
                '<tr>' +
                    '<td style="text-align: center;"><button id="no">No, not yet</button></td>' +
                    '<td style="text-align: center;"><button id="yes">Yes, why not?</button></td>' +
                '</tr>' +
            '</table>' +
        '</div>');
        $('#no').click(function () {
            $('#dialog').remove();
            history.back();
        });
        $('#yes').click(function () {
            $('#dialog').remove();
            $('#blackout').fadeOut(2000, function () {
                $('#blackout').remove();
            });
        });
    }
});
--  pecoes  13:19, March 24, 2012 (UTC) 
It seems not to be working. I put a <script> tag around it, and that made the code dissappear. (Link to script, link to page) Thanks, Iggyvolz 13:43, March 24, 2012 (UTC)
There are no <script> tags in Wikicode. You need to add the code to one of the dedicated JavaScript pages. --  pecoes  14:07, March 24, 2012 (UTC) 
Is this CSS or JS? Iggyvolz 14:47, March 24, 2012 (UTC)
JS --  pecoes  15:06, March 24, 2012 (UTC) 
I tried it on MediaWiki:Common.js, but nothing happened. I'll be back in about 2hrs, I can make you admin of the wiki to put it in if you want. Thanks, Iggyvolz 15:09, March 24, 2012 (UTC)
Okay. Make me an admin. But don't forget to remove my privileges afterwards! --  pecoes  15:19, March 24, 2012 (UTC) 
This page should work now. You might have to refresh your browser's cache and/or wait a while before it starts to work. --  pecoes  15:53, March 24, 2012 (UTC) 

(Reset indent)

It's still not working, tried purging, clearing cache, and deleting browsing history. Is it coming up for you? Iggyvolz 19:25, March 24, 2012 (UTC)

Works fine for me. What browser are you using? TK999 19:30, March 24, 2012 (UTC)
IE8. Used a different browser and it worked fine. However, I don't understand why it won't work in Internet Explorer. Iggyvolz 19:35, March 24, 2012 (UTC)
I think it may have been related to jQuery since Internet Explorer 8 did not pass the Acid3 standards test. TK999 19:44, March 24, 2012 (UTC)
I've only tested it with IE9. It works well there. But, you're right: It does not seem to work with IE7 or IE8. That sucks. I kinda thought with jQuery such problems were a thing of the past. :( --  pecoes  20:01, March 24, 2012 (UTC) 
I'll be getting IE9 soon then. Thanks for all the help, Iggyvolz 20:06, March 24, 2012 (UTC)

(Reset indent)

It appears that $('title').text() doesn't work in IE<9. If that's true, that's easy to fix. Replace this:

if (/spoiler/i.test($('title').text())) {

with this:

if (/spoiler/i.test(document.title)) {

But let's wait 2hours until the browershots are finished. Who knows? There might be other "interesting" results... --  pecoes  20:14, March 24, 2012 (UTC) 

Is there an example of the JS above working somewhere? -- Fandyllic (talk · contr) 27 Mar 2012 1:13 PM Pacific
I think Iggy made some additional changes, so if you want to see just the initial script, go here. --  pecoes  21:55, March 27, 2012 (UTC) 
Yeah, it works nicely on your sandbox wiki, but you might want to modify the JS so it doesn't activate when searching for "Spoiler". -- Fandyllic (talk · contr) 27 Mar 2012 4:49 PM Pacific
Done. --  pecoes  01:28, March 28, 2012 (UTC) 
Very nice. You should consider putting this on the Dev wiki. -- Fandyllic (talk · contr) 28 Mar 2012 12:04 PM Pacific
Sure. Why not? It's here now: w:c:dev:SpoilerAlert.
I've added configuration options for the dialog text and the test function.
The code also uses a cookie now. If the visitor answers the "Do you really want to see this page?" question with yes, the articleId is added to the cookie. The next time the visitor returns to the page, the dialog won't show. --  pecoes  01:16, March 29, 2012 (UTC) 

Around Wikia's network

Random Wiki