User talk:Gerbrant/mng/decache.js

From OpenWetWare
Jump to: navigation, search
Gerbrant.mng.decache
This module provides a way to link to an external application to remove scripts from the cache.

Usage

When a JavaScript page is open, a "Decache" link appears in the toolbox. When clicked a popup opens, showing a list of loaded scripts. Check those you want to remove from the cache (i.e. those you have modified recently) and click the link below the list.

The following scripts are available in the list:

  1. The current JavaScript page (selected by default).
  2. Your monobook script.
  3. All scripts specified at Gerbrant.fw.load.
  4. All other scripts loaded using loadModule(s) after this script is loaded. For this reason, it's usually best to load this script before all other scripts with dependencies.

That the "Decache" link appears in the toolbar, and only when on a JavaScript page, is default behaviour. This can be customized using settings.

Installation

This script will only work in conjunction with Gerbrant.fw (documentation). If you're already using it, just add "Gerbrant.mng.decache" to the start of the list of modules to load, otherwise paste the following in your monobook.js:

Gerbrant = {fw: {load: [

"Gerbrant.mng.decache"

]}}

document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Gerbrant/fw.js&action=raw&ctype=text/javascript&dontcountme=s"><\u002fscript>');

Exports

Note: this module by default exports nothing when not at a Javascript page.

show()
Shows the window.
caption
String, "Decache".

Settings

onAllPages
If defined and true, this module will load on all pages, not only on JavaScript pages.
notInToolbox
If defined and true, this module won't appear in the toolbox, and you'll have to activate it in a different manner.

Example:

{
    onAllPages: true,
    notInToolbox: true
}

This example can be tested by inserting it in your monobook.js:

Gerbrant = { ...
mng: { ...
decache: <example>
... } ... }

Example implementation of protocol

In Visual Basic this protocol can be implemented rather trivially:

VERSION 4.00
Begin VB.Form Confirm 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Tijdelijke bestanden verwijderen"
   ClientHeight    =   3240
   ClientLeft      =   3255
   ClientTop       =   5745
   ClientWidth     =   4800
   BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
      Name            =   "Verdana"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Height          =   3690
   Left            =   3195
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3240
   ScaleWidth      =   4800
   ShowInTaskbar   =   0   'False
   Top             =   5355
   Width           =   4920
   Begin VB.CommandButton Cancel 
      Caption         =   "Annuleren"
      Height          =   345
      Left            =   2820
      TabIndex        =   3
      Top             =   2640
      Width           =   1125
   End
   Begin VB.CommandButton OK 
      Caption         =   "OK"
      Height          =   345
      Left            =   885
      TabIndex        =   2
      Top             =   2640
      Width           =   1125
   End
   Begin VB.ListBox UrlList 
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1425
      Left            =   240
      TabIndex        =   1
      Top             =   840
      Width           =   4320
   End
   Begin VB.Label Notice 
      AutoSize        =   -1  'True
      Caption         =   "De volgende tijdelijke bestanden zullen worden verwijderd:"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   4140
   End
End
Attribute VB_Name = "Confirm"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function DeleteUrlCacheEntry _
    Lib "WinINet" _
    Alias "DeleteUrlCacheEntryA" _
    (ByVal Url As String) As Long

Private Sub Cancel_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim T As String, P As Long
T = Command
If T = vbNullString Then
    CreateRegFiles
    Unload Me
Else
    Left = (Screen.Width - Width) \ 2
    Top = (Screen.Height - Height) \ 3
    If UCase(Left(T, 17)) = "GERBRANT-DECACHE:" Then
        T = Mid(T, 18)
    End If
    Do
        P = InStr(T, "#")
        If P = 0 Then Exit Do
        UrlList.AddItem Left(T, P - 1)
        T = Mid(T, P + 1)
    Loop
    UrlList.AddItem T
End If
End Sub

Private Sub OK_Click()
Dim I As Long, Problem As Boolean
I = UrlList.ListCount
While I
    I = I - 1
    If DeleteUrlCacheEntry(UrlList.List(I)) Then
        UrlList.RemoveItem I
    ElseIf Err.LastDllError <> 2 Then
        Problem = True
    End If
Wend
If Problem Then
    MsgBox "Bestanden die in gebruik zijn kunnen niet worden verwijderd. Deze zijn gemarkeerd en zullen worden verwijderd zodra dit mogelijk is.", vbOKOnly, "Bestanden niet verwijderd"
    Exit Sub
End If
Unload Me
End Sub

Private Sub CreateRegFiles()
Dim T As String, S As String, P As Long
S = App.Path
Do
    P = InStr(S, "\")
    If P = 0 Then Exit Do
    T = T & Left(S, P) & "\"
    S = Mid(S, P + 1)
Loop
T = "@=""\""" & T & S & "\\Decache.exe\"""

Open App.Path & "\install.reg" For Output As #1
Print #1, "REGEDIT4"
Print #1,
Print #1, "[HKEY_CLASSES_ROOT\gerbrant-decache]"
Print #1, "@=""URL:Decache-protocol"""
Print #1, """EditFlags""=hex:02,00,00,00"
Print #1, """URL Protocol""="""""
Print #1,
Print #1, "[HKEY_CLASSES_ROOT\gerbrant-decache\DefaultIcon]"
Print #1, T; """"
Print #1,
Print #1, "[HKEY_CLASSES_ROOT\gerbrant-decache\shell]"
Print #1,
Print #1, "[HKEY_CLASSES_ROOT\gerbrant-decache\shell\open]"
Print #1,
Print #1, "[HKEY_CLASSES_ROOT\gerbrant-decache\shell\open\command]"
Print #1, T; " %1"""
Close

Open App.Path & "\uninstall.reg" For Output As #1
Print #1, "REGEDIT4"
Print #1,
Print #1, "[-HKEY_CLASSES_ROOT\gerbrant-decache]"
Close
End Sub

As you can see, when you start the program without command-line arguments, it creates two regfiles which can be used to install or uninstall the protocol handler. Have fun.